Re: [Hampshire] Cron script problem

2010-10-12 Thread Anton Piatek
On 11 October 2010 23:45, Vic l...@beer.org.uk wrote:

 After adding the folder that holds the file to
 $PATH and then changing crontab to run from /folder/file.sh it would not
 run But when I changed it to /folder/file it ran?

 Yes - exactly,

 The name of your script was day1, IIRC. That's its name - calling it
 day1.sh doesn't work, because that's the name of a completely different
 file (that doesn't exist).

 You *also* need to tell the OS where to find your script - either by
 giving it an explicit pathname, or letting it find it by searching along
 $PATH - but that's entirely secondary to the problem of needing to use the
 right name in the first place.

 I understood the part about the file did not exist, my problem was finding
 out why it thought it did not exist

 Simply because it didn't exist. Your script was called day1. day1.sh
 is not the same file.

I think perhaps an explanation that the file extension in linux
generally does not affect what the OS will do with the file. In gui
window managers, the extension is sometimes used to work out which
application to open it with, but when it comes to command line usage,
in particular executable scripts, the extension is purely a hint for
users.

If a file has the executable bit, then the OS will try and run it when
asked. If it is a text file, then it looks a the first line. If the
first line is #!/bin/bash (usually referred to as she-bang /bin/bash)
then when you run ./script the OS will ask /bin/bash to run the
contents of the file, even if the file has an extension that might
suggest something else

Anton

-- 
Anton Piatek
email: an...@piatek.co.uk
blog/photos:            http://www.strangeparty.com
pgp: [74B1FA37]    (http://www.strangeparty.com/anton.asc)
fingerprint: 7401 96D3 E037 2F8F 5965  A358 4046 71FD 74B1 FA37

No trees were destroyed in the sending of this message, however, a
significant number of electrons were terribly inconvenienced.

--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--


Re: [Hampshire] Cron script problem

2010-10-11 Thread Tim
On Tuesday 05 October 2010 21:52:53 Vic wrote:
 OK - here are a couple of problems...

  crontab -l
 
  0 0 * * 1 /backup.day1.sh # Day 1 backup
  (the same was repeated for each of the other 4 scripts)

 Note that this is trying to run /backup.day1.sh . You probably don't mean
 that; the dot after backup would appear to be a typo (should it be a
 slash?)

  ls -l /backup
  -rwxrwxr-x 1 root root 357 2010-10-05 20:43 day1

 And here, your script is called day1, not day1.sh.

  I think
  I may need to change some of the permission so only root can run and
  write?

 Only root can write those. Others may read/execute - it's up to you
 whether you see a problem with that (depends on the content of the
 script).

  I looked in mail and yes there were mails regarding cron there. Basicly
  it is
  saying /backups/day1 file not found

 Yep. And now you know why :-)

  So the problem is how do I tell it to
  chnage to the backup folder and then run the script?

 No. Relying on CWD is usually a problem - a change to your setup later can
 cause subtle problems. Better either to be *explicit* about what you want
 to run (which your script attempts to be, but fails), or to ensure your
 executables will be properly in PATH.

  I should point out (if it makes any difference) that I am access the
  server via vnc

 None at all.

 Vic.


 --
 Please post to: Hampshire@mailman.lug.org.uk
 Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
 LUG URL: http://www.hantslug.org.uk
 --

Thanks for all the help I have now have it working, not sure exactly what the 
problem was I think it was one or two minor problems

Tim

--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--


Re: [Hampshire] Cron script problem

2010-10-11 Thread Keith Edmunds
On Mon, 11 Oct 2010 18:25:36 +0100, xendis...@gmx.com said:

 Thanks for all the help I have now have it working, not sure exactly
 what the problem was

Two comments, not meant to sound harsh (but I'm aware that they may do).

Firstly, there's no need to quote an entire thread just to say that you
have things working now.

Secondly, you can approach Linux from a number of perspectives, one of
which is to try to understand how it works. That isn't necessarily easy:
it's a complex system and I maintain that I learn something new about
Linux every week (and I've worked with it full time for ten years, and
used it for a lot longer). But if you do want to understand it, I would
suggest that when you come across a problem such as you had, and you
receive advice about how to solve it, you should try one thing at a time.
That will allow you to see what does and does not work (even the 'does not
work' may teach you something), and it will also allow you to teach others
when you thank Fred, Bill, Alice and Susan for their advice, and say that
it turned out to be Susan's idea of doing XXX that fixed it.

Keith

--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--


Re: [Hampshire] Cron script problem

2010-10-11 Thread Tim
On Monday 11 October 2010 18:41:25 Keith Edmunds wrote:

 Two comments, not meant to sound harsh (but I'm aware that they may do).

 Firstly, there's no need to quote an entire thread just to say that you
 have things working now.

 Secondly, you can approach Linux from a number of perspectives, one of
 which is to try to understand how it works. That isn't necessarily easy:
 it's a complex system and I maintain that I learn something new about
 Linux every week (and I've worked with it full time for ten years, and
 used it for a lot longer). But if you do want to understand it, I would
 suggest that when you come across a problem such as you had, and you
 receive advice about how to solve it, you should try one thing at a time.
 That will allow you to see what does and does not work (even the 'does not
 work' may teach you something), and it will also allow you to teach others
 when you thank Fred, Bill, Alice and Susan for their advice, and say that
 it turned out to be Susan's idea of doing XXX that fixed it.

 Keith

 --
 Please post to: Hampshire@mailman.lug.org.uk
 Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
 LUG URL: http://www.hantslug.org.uk
 --

OK I have debated about replying and have decided to do so, but I 
don't wish to turn this into a bun fight but I did find your comments rather 
grating.

Firstly I will put my hands up and apologise for the full quote, that was a 
schoolboy error. I was in a bit of a rush and wanted to thank those that had 
taken the time to rply to my request for help. Unfortunately thanking people on 
userlist like this one is something I don't do enough of. 

In resolving this problem with the help of all those replies I got, some of 
which made suggestion which I had forgotten about and when tried\checked the 
results helped. I have learnt the following, configure crontab from the command 
line, save text file (in this case crontab) at the command line, add folders to 
the $PATH. I am a product of the gui era while I understand the power and the 
complexity of the cli but I am all for an easy life and if the gui will give me 
that then that is where I will live.

So all in all I did learn a lot, but as I said in my thank you post, I am not 
sure exactly what I did that resolved the problem. I think it was one,  two 
maybe even three little things that was stopping it from working properly (like 
the file I wanted crontab to run only needed the file name not the .sh on the 
end of it), ultimately each replied was another piece in a jigsaw which I was 
trying to complete without a picture to refer to. Unfortunately I have not had 
a lot of time to resolve the problem hence the time it has taken to resolve a 
fairly simple problem.

Linux is complex (but so is any OS), but I have pretty much taught myself to 
run, install and resolve problems I come across. My linux usage is a hobby and 
while I have been playing with Linux from Suse 6 days it has been my main OS at 
home for at least 6 years. I have asked question here and else where and as you 
learn something new about linux everyday. But I don't see why you feel the need 
to think that I have not learnt anything from the replies I had been given, I 
did not continually come back asking what the next step was, I asked question 
and learnt from the suggestion I was given and the result I obtained, hence I 
resolved my problem, not quickly, but I resolved it

Tim



--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--


Re: [Hampshire] Cron script problem

2010-10-11 Thread Vic

 (like the file I wanted crontab to run only needed the file name not the
 .sh on the end of it)

That *is* the filename.

foo.sh is the name of a file. foo is the name of another file. These are
not the same file.

If you tell the OS to execute a file called foo.sh, then foo.sh is the
name of the file it will execute. It will not attempt to execute foo,
because that is not the file you told it to run...

This was the main problem I saw with your cron scripts - you were telling
it to execute a file that did not exist.

HTH

Vic.


--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--


Re: [Hampshire] Cron script problem

2010-10-11 Thread Tim
On Monday 11 October 2010 22:28:06 Vic wrote:
  (like the file I wanted crontab to run only needed the file name not the
  .sh on the end of it)

 That *is* the filename.

 foo.sh is the name of a file. foo is the name of another file. These are
 not the same file.

 If you tell the OS to execute a file called foo.sh, then foo.sh is the
 name of the file it will execute. It will not attempt to execute foo,
 because that is not the file you told it to run...

 This was the main problem I saw with your cron scripts - you were telling
 it to execute a file that did not exist.

 HTH

 Vic.


 --
 Please post to: Hampshire@mailman.lug.org.uk
 Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
 LUG URL: http://www.hantslug.org.uk
 --

OK, when I posted the request for help I tried both file.sh and file in crontab 
and neither of them worked. After adding the folder that holds the file to 
$PATH and then changing crontab to run from /folder/file.sh it would not run 
But when I changed it to /folder/file it ran?

I understood the part about the file did not exist, my problem was finding out 
why it thought it did not exist

Tim

--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--


Re: [Hampshire] Cron script problem

2010-10-11 Thread Vic

 After adding the folder that holds the file to
 $PATH and then changing crontab to run from /folder/file.sh it would not
 run But when I changed it to /folder/file it ran?

Yes - exactly,

The name of your script was day1, IIRC. That's its name - calling it
day1.sh doesn't work, because that's the name of a completely different
file (that doesn't exist).

You *also* need to tell the OS where to find your script - either by
giving it an explicit pathname, or letting it find it by searching along
$PATH - but that's entirely secondary to the problem of needing to use the
right name in the first place.

 I understood the part about the file did not exist, my problem was finding
 out why it thought it did not exist

Simply because it didn't exist. Your script was called day1. day1.sh
is not the same file.

Vic.


--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--


Re: [Hampshire] Cron script problem

2010-10-05 Thread Vic

 So my first question is, where should these 5 scripts reside (they
 currently live in a folder called backup in the root of the file sytem)

Wherever you like. Just make sure you tell cron the full pathname to the
script = ./day1 is unlikely to work, because that means the day1 script
in the current directory, and your current directory might not be what
you want it to be...

 How do I get cron to run them and where do I find any logs files that may
 point to what is going wrong?

Check root's email. cron can mail anyone you tell it to, but if you
haven't specified someone (and I doubt that you have), root tends to get
the reports.

Vic.


--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--


Re: [Hampshire] Cron script problem

2010-10-05 Thread John Cooper

On 05/10/10 18:25, Vic wrote:



So my first question is, where should these 5 scripts reside (they
currently live in a folder called backup in the root of the file sytem)


Wherever you like. Just make sure you tell cron the full pathname to the
script = ./day1 is unlikely to work, because that means the day1 script
in the current directory, and your current directory might not be what
you want it to be...


How do I get cron to run them and where do I find any logs files that may
point to what is going wrong?


Check root's email. cron can mail anyone you tell it to, but if you
haven't specified someone (and I doubt that you have), root tends to get
the reports.



To add to Vic's comments, the script can be anywhere but if you are 
running it from root cron, it must be owned by root and not world 
writable. Otherwise, anyone could modify the script and it would then 
run as root, opening all kinds of security risks. /usr/local/bin is a 
good place for root owned cron scripts. If you are running from your own 
account, the script can be anywhere but only writable by you. Check 
/etc/cron.allow and /etc/cron.deny don't exist, or if they do your 
account is in /etc/cron.allow.


Make sure crond is running.

 $ ps ax | grep cron
 1950 ?Ss 0:00 crond

I normally change /etc/aliases root: line to my account

# Person who should get root's mail
root:   user1

and then run newaliases commands to make it live (creates the binary 
database). You will then get any output from the cron jobs as an email. 
If the cron doesn't output anything, you won't get an email. So you 
could put in the cron script :-


echo Start of cron myjob

and this will be emailed to root (aliased to you) when the cron runs.

You could also run logger and tail /var/log/messages

logger -t mycron1 start of cron


tail -f /var/log/messages

Oct  5 18:45:36 myserver mycron1: start of cron


John.
--
--
Discover Linux - Open Source Solutions to Business and Schools
http://discoverlinux.co.uk
--

--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--


Re: [Hampshire] Cron script problem

2010-10-05 Thread Stuart Sears
On 05/10/10 18:49, John Cooper wrote:
 On 05/10/10 18:25, Vic wrote:
[snip excellent advice]

 How do I get cron to run them and where do I find any logs files that
 may
 point to what is going wrong?

show us the output of
crontab -l

as the user who owns these scripts?
plus

ls -l /path/to/scripts

 Check root's email. cron can mail anyone you tell it to, but if you
 haven't specified someone (and I doubt that you have), root tends to get
 the reports.

well, only if the jobs are in root's crontab.
...which is just plain wrong - that's what /etc/cron.d is for (okay,
that's a matter of opinion and a little off-track for this)

[...snip other excellent advice...]

I'm not sure exactly what webmin does with cron.

But setting it up manually could be achieved with a bit of advice (and
it's a good learning experience too)

https://help.ubuntu.com/community/CronHowto

(while I don't agree with all of it, it's mostly pretty good)

Regards,

Stuart
-- 
Stuart Sears RHCA etc.
It's today! said Piglet.
My favourite day, said Pooh.

--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--


Re: [Hampshire] Cron script problem

2010-10-05 Thread Tim
On Tuesday 05 October 2010 19:15:06 Stuart Sears wrote:
 On 05/10/10 18:49, John Cooper wrote:
  On 05/10/10 18:25, Vic wrote:

 [snip excellent advice]

  How do I get cron to run them and where do I find any logs files that
  may
  point to what is going wrong?

 show us the output of
 crontab -l

 as the user who owns these scripts?
 plus

 ls -l /path/to/scripts

  Check root's email. cron can mail anyone you tell it to, but if you
  haven't specified someone (and I doubt that you have), root tends to get
  the reports.

 well, only if the jobs are in root's crontab.
 ...which is just plain wrong - that's what /etc/cron.d is for (okay,
 that's a matter of opinion and a little off-track for this)

 [...snip other excellent advice...]

 I'm not sure exactly what webmin does with cron.

 But setting it up manually could be achieved with a bit of advice (and
 it's a good learning experience too)

 https://help.ubuntu.com/community/CronHowto

 (while I don't agree with all of it, it's mostly pretty good)

 Regards,

 Stuart

OK in no particular order I tried the commands suggested with the following 
results

ps ax | grep crond
4010 pts/0  S+  0:00 grep --color=auto crond (crond was written in red 
typeface)

So that tell me crond is running

crontab -l

0 0 * * 1 /backup.day1.sh # Day 1 backup
(the same was repeated for each of the other 4 scripts)

This tell me that at midnight on days 1 to 5 the script will run, yes?

ls -l /backup
-rwxrwxr-x 1 root root 357 2010-10-05 20:43 day1
(the same was repeated for each of the other 4 scripts)

This tell that root owns the folder and each of the 5 scripts there in, I think 
I may need to change some of the permission so only root can run and write?

In regards to webmin, it just make it easy for me to administrate the control 
of 
the server as opposed to cli

I looked in mail and yes there were mails regarding cron there. Basicly it is 
saying /backups/day1 file not found So the problem is how do I tell it to 
chnage to the backup folder and then run the script?

I should point out (if it makes any difference) that I am access the server via 
vnc

Tim 



--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--


Re: [Hampshire] Cron script problem

2010-10-05 Thread Martin Elliott
The output of 'the ps ax | grep crond' is just showing you the grep command
running, and not the actual cron daemon.  I'm sure I've seen some systems
where cron is not running as a daemon, but I may be wrong, and this may have
been a very long time ago...  But if you're getting emails about cron, it
must be processing your cronjobs.

Your cronjob needs to contain the full path to the script - at the moment it
looks like this has
/backup.day1.sh - which I think may need to be /backup/day1.sh based on
other comments you've
made.

Yes you need to change the permissions.   I presume these jobs are running
under root's crontab, so (as root) you could chmod 700 /backup/day*.sh to
change them all to read/write/execute for root, and with no permission for
users in root's group, or other users of the system.

VNC won't be making any difference at least :-)

On 5 October 2010 15:13, Tim xendis...@gmx.com wrote:

  On Tuesday 05 October 2010 19:15:06 Stuart Sears wrote:
  On 05/10/10 18:49, John Cooper wrote:
   On 05/10/10 18:25, Vic wrote:
 
  [snip excellent advice]
 
   How do I get cron to run them and where do I find any logs files that
   may
   point to what is going wrong?
 
  show us the output of
  crontab -l
 
  as the user who owns these scripts?
  plus
 
  ls -l /path/to/scripts
 
   Check root's email. cron can mail anyone you tell it to, but if you
   haven't specified someone (and I doubt that you have), root tends to
 get
   the reports.
 
  well, only if the jobs are in root's crontab.
  ...which is just plain wrong - that's what /etc/cron.d is for (okay,
  that's a matter of opinion and a little off-track for this)
 
  [...snip other excellent advice...]
 
  I'm not sure exactly what webmin does with cron.
 
  But setting it up manually could be achieved with a bit of advice (and
  it's a good learning experience too)
 
  https://help.ubuntu.com/community/CronHowto
 
  (while I don't agree with all of it, it's mostly pretty good)
 
  Regards,
 
  Stuart

 OK in no particular order I tried the commands suggested with the following
 results

 ps ax | grep crond
 4010 pts/0  S+  0:00 grep --color=auto crond (crond was written in
 red typeface)

 So that tell me crond is running

 crontab -l

 0 0 * * 1 /backup.day1.sh # Day 1 backup
 (the same was repeated for each of the other 4 scripts)

 This tell me that at midnight on days 1 to 5 the script will run, yes?

 ls -l /backup
 -rwxrwxr-x 1 root root 357 2010-10-05 20:43 day1
 (the same was repeated for each of the other 4 scripts)

 This tell that root owns the folder and each of the 5 scripts there in, I
 think
 I may need to change some of the permission so only root can run and write?

 In regards to webmin, it just make it easy for me to administrate the
 control of
 the server as opposed to cli

 I looked in mail and yes there were mails regarding cron there. Basicly it
 is
 saying /backups/day1 file not found So the problem is how do I tell it to
 chnage to the backup folder and then run the script?

 I should point out (if it makes any difference) that I am access the server
 via
 vnc

 Tim



 --
 Please post to: Hampshire@mailman.lug.org.uk
 Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
 LUG URL: http://www.hantslug.org.uk
 --

--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--

Re: [Hampshire] Cron script problem

2010-10-05 Thread Martin Elliott
Please also bear in mind that running the script from the /backup directory
itself - with ./day1.sh - may yeild different results than running it from
another working directory with /backup/day1.sh

You may want to adjust your script to cd to whatever working directory you
want the script to use, as when running as a cronjob it won't be moving into
that directory before executing the script.

I hope that made sense, it has been a long day!




On 5 October 2010 15:34, Martin Elliott sli...@slipnet.org.uk wrote:

 The output of 'the ps ax | grep crond' is just showing you the grep command
 running, and not the actual cron daemon.  I'm sure I've seen some systems
 where cron is not running as a daemon, but I may be wrong, and this may have
 been a very long time ago...  But if you're getting emails about cron, it
 must be processing your cronjobs.

 Your cronjob needs to contain the full path to the script - at the moment
 it looks like this has
 /backup.day1.sh - which I think may need to be /backup/day1.sh based on
 other comments you've
 made.

 Yes you need to change the permissions.   I presume these jobs are running
 under root's crontab, so (as root) you could chmod 700 /backup/day*.sh to
 change them all to read/write/execute for root, and with no permission for
 users in root's group, or other users of the system.

 VNC won't be making any difference at least :-)

   On 5 October 2010 15:13, Tim xendis...@gmx.com wrote:

  On Tuesday 05 October 2010 19:15:06 Stuart Sears wrote:
  On 05/10/10 18:49, John Cooper wrote:
   On 05/10/10 18:25, Vic wrote:
 
  [snip excellent advice]
 
   How do I get cron to run them and where do I find any logs files
 that
   may
   point to what is going wrong?
 
  show us the output of
  crontab -l
 
  as the user who owns these scripts?
  plus
 
  ls -l /path/to/scripts
 
   Check root's email. cron can mail anyone you tell it to, but if you
   haven't specified someone (and I doubt that you have), root tends to
 get
   the reports.
 
  well, only if the jobs are in root's crontab.
  ...which is just plain wrong - that's what /etc/cron.d is for (okay,
  that's a matter of opinion and a little off-track for this)
 
  [...snip other excellent advice...]
 
  I'm not sure exactly what webmin does with cron.
 
  But setting it up manually could be achieved with a bit of advice (and
  it's a good learning experience too)
 
  https://help.ubuntu.com/community/CronHowto
 
  (while I don't agree with all of it, it's mostly pretty good)
 
  Regards,
 
  Stuart

 OK in no particular order I tried the commands suggested with the
 following
 results

 ps ax | grep crond
 4010 pts/0  S+  0:00 grep --color=auto crond (crond was written in
 red typeface)

 So that tell me crond is running

 crontab -l

 0 0 * * 1 /backup.day1.sh # Day 1 backup
 (the same was repeated for each of the other 4 scripts)

 This tell me that at midnight on days 1 to 5 the script will run, yes?

 ls -l /backup
 -rwxrwxr-x 1 root root 357 2010-10-05 20:43 day1
 (the same was repeated for each of the other 4 scripts)

 This tell that root owns the folder and each of the 5 scripts there in, I
 think
 I may need to change some of the permission so only root can run and
 write?

 In regards to webmin, it just make it easy for me to administrate the
 control of
 the server as opposed to cli

 I looked in mail and yes there were mails regarding cron there. Basicly it
 is
 saying /backups/day1 file not found So the problem is how do I tell it to
 chnage to the backup folder and then run the script?

 I should point out (if it makes any difference) that I am access the
 server via
 vnc

 Tim



 --
 Please post to: Hampshire@mailman.lug.org.uk
 Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
 LUG URL: http://www.hantslug.org.uk
 --



--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--