[X-Unix] Cron problem - Again

Robert Frank robert.frank at unibas.ch
Fri Jun 24 01:42:04 PDT 2005


With the new systemV like cronjob handling, every user has his/her  
own cronjob. So cron will run as the user who initiates crontab -e,  
unless you specify a different user with the -u option, which only  
the root user may do.

The BSD cronjob handling is still available, you just edit /etc/ 
crontab using any editor. Entries in that file will be run as root.

As to the script, why not put the entire command into the script and  
then just run that from cron?

/users/marleygraham/screenpict may contain:

#!/bin/bash
/usr/sbin/screencapture /full/path/to/file/mg`/bin/date +%r | /usr/ 
bin/awk '{ print $1}'`
(This is the power of shell scripting:
first, I append the date string directly to the letters 'mg' by  
calling the commands date and awk in backquotes `..`
then I execute the screencapture program with that argument.
Within the backquotes, I pipe (|) the date command to awk which  
extracts the first field.

However, this is still a cludge, as we don't need awk (a huge thing!):

/usr/sbin/screencapture /full/path/to/file/mg`/bin/date +%H:%M%S`

or, if you must have the 12 hour clock (not recommended in this case,  
as this will overwrite the files!):

/usr/sbin/screencapture /full/path/to/file/mg`/bin/date +%I:%M%S`

Now, of course, you can go and put this into cron directly, but then  
you will have to edit crontab each time you want to change something.  
Keeping the commands in a file will allow you to
make changes and check them without modifying the cron entry.

Make sure the file is executable by the user with which cron is running.
And one more point: in your solution,  the file to write to is given  
as 'mg...', i.e. as a relative path. It will be wriiten to the  
directory from which cron runs the script. And this need not be the  
place of the script. So: provide the full path to the files to be on  
the safe side!


On 23 Jun 2005, at 23:54, x-unix- 
request at listserver.themacintoshguy.com wrote:

> I have my screencapture program running under cron on my machine. So
> I figured I would do the same on some client machines for which I
> have set up an admin account. But it doesn't work on the client
> machines. Here is what I have:
>
> On my machine:
> $ crontab -l
> 0,30 7-16 * * 1-6 /users/marleygraham/screenpict
>
> Where screenpict is the script:
> #!/bin/bash
> /usr/sbin/screencapture mg$(/users/marleygraham/exacttime)
> exit
>
> And exacttime is the script:
> #!/bin/bash
> /bin/date +%r > tempdate
> awk '{print $1}' tempdate
> rm tempdate
> exit
>
> On the client machine, I have set up an admin user isadmin. I logged
> onto the client over ssh and set up the cron job using crontab -e.
> Then I copied the scripts to the  client using ARD copy, changed the
> owner to isadmin, and edited to change the username. So on the client
> I have:
>
> n$ crontab -l
> 0,30 7-16 * * 1-6 /screenpicsa
>
> Where screenpicsa is:
> #!/bin/bash
> /usr/sbin/screencapture /isscreen$(/exacttime)
> exit
>
> And exacttime is:
> #!/bin/bash
> /bin/date +%r > tempdate
> awk '{print $1}' tempdate
> rm tempdate
> exit
>
> The files look like:
> -rwxr-xr-x    1 isadmin  isadmin       82 22 Jun 16:40 exacttime
> -rwxr-xr-x    1 isadmin  isadmin       67 23 Jun 08:21 screenpicsa
>
> I am not getting any files generated by cron. Any ideas why?
>
> Marley Graham
> Aqua-Flo Supply
> ==============
>
>
>

Departement Informatik   FGB   tel   +41 (0)61 267 14 66
Universität Basel                          fax. +41 (0)61 267 14 61
Robert Frank
Klingelbergstrasse 50                 Robert.Frank at unibas.ch
CH-4056 Basel
Switzerland                                   http:// 
www.informatik.unibas.ch/personen/frank_r.html




More information about the X-Unix mailing list