1848084 Members
6924 Online
104022 Solutions
New Discussion

Re: crontab question

 
thebeatlesguru
Regular Advisor

crontab question

user pin write a shell script in /home/pin to check system ,and root do these things as following:
crontab -e
30 08 * * * "su - pin -c /home/pin/shellname"

but cron doesnot work ,there should be some messages to inform me about the check info,but i cannot find these messages.

from book ,i find something about cron:cron only use /usr/bin/sh surrounding and can not use your surrounding. i can understand these words exactly,does it mean that i cannot use a shell script in crontab??
hihi
13 REPLIES 13
Steven Sim Kok Leong
Honored Contributor

Re: crontab question

Hi,

Try specifying the full path for su in the crontab ie. /usr/bin/su.

Hope this helps. Regards.

Steven Sim Kok Leong
Peter Kloetgen
Esteemed Contributor

Re: crontab question

Hi Guru,

of course you can use shellscripts with cron. Why the hell should we need cron else? First:

the messages go to the mail account of the user who starts the cronjob. If you want messages to come to another point, you have to redirect them.

cronjob >/dev/pts/0 for example

if you write a shellscript, the first line should be:

# !/usr/bin/desired_shell

to show the script which shell should interpret it

then your cron job shoul work....


Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
Carlos Fernandez Riera
Honored Contributor

Re: crontab question

Change:

30 08 * * * "su - pin -c /home/pin/shellname"

to
30 08 * * * su - pin -c "/home/pin/shellname"


unsupported
Kenny Chau
Trusted Contributor

Re: crontab question

Maybe you can try this:

30 08 * * * /usr/bin/su - pin -c "/home/pin/shellname"

Hope this helps.
Kenny.
Kenny
Steven Sim Kok Leong
Honored Contributor

Re: crontab question

Hi,

The fault lies with your double-quotes. I just tested. With the quotes, the whole string will be taken as a command.

Hope this helps. Regards.

Steven Sim Kok Leong
John Strang
Regular Advisor

Re: crontab question

Have you checked the cron log, to ehsure that the job is running? Log is
/var/adm/cron/log

This should show the start & finish times of the cron job.

John
If you never make a mistake you'll never make anything.
thebeatlesguru
Regular Advisor

Re: crontab question

i have try all suggestiones,however it still does not work.
following is my date:
# crontab -e
"/var/tmp/aaaa10044"
45 16 * * * usr/bin/su - pin -c "/home/pin/ok"

/var/tmp/aaaa10044" 1 line, 39 characters
warning: commands will be executed using /usr/bin/sh
# crontab -l
45 16 * * * usr/bin/su - pin -c "/home/pin/ok"
# date -u
Wed Feb 20 16:44:12 UTC 2002
# date -u
Wed Feb 20 16:45:20 UTC 2002
# cat log
! *** cron ????????? *** pid = 1088 Tue Feb 19 12:10:13 EAT 2002
> CMD: /home/pin/ok
> root 9364 c Wed Feb 20 22:48:17 EAT 2002
< root 9364 c Wed Feb 20 22:48:17 EAT 2002

after 16:45,i use pin user ,but there is no mail.

hihi
Peter Kloetgen
Esteemed Contributor

Re: crontab question

Hi Guru,

did you check the first line of script?

# !/path_to_shell_to_interpret_the_script

you do a switchuser to desired user. Do you have an entry in the cron.allow for that user?
A su - changes identity and also the environment to the users environment. Which shell does the user have as entry in the /etc/passwd- file?

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
Steven Sim Kok Leong
Honored Contributor

Re: crontab question

Hi,

You missed out the /.

Change:

45 16 * * * usr/bin/su - pin -c "/home/pin/ok"

To:

45 16 * * * /usr/bin/su - pin -c "/home/pin/ok"

Hope this helps. Regards.

Steven Sim Kok Leong
thebeatlesguru
Regular Advisor

Re: crontab question

look here:


tsrad 30> date
Thu Feb 21 17:10:24 EAT 2002
tsrad 31> date -u
Thu Feb 21 09:10:26 UTC 2002

which time should be used in crontab?
hihi
A. Clay Stephenson
Acclaimed Contributor

Re: crontab question

Hi:

Do this:

cat /etc/TIMEZONE. This will display the default system TZ setting and whatever that is, that is what you use.

If it ain't broke, I can fix that.
thebeatlesguru
Regular Advisor

Re: crontab question


cat TIMEZONE
TZ=EAT-8
export TZ
tsrad 45> date
Thu Feb 21 17:57:42 EAT 2002
tsrad 46> date -u
Thu Feb 21 09:58:00 UTC 2002

does it mean that i shoule use 09:58:00 ?
hihi
Deepak Extross
Honored Contributor

Re: crontab question

Since you're only testing it out, why not set the job to run every 5 minutes? That way you dont have to worry about your TZ setting.
05 * * * * /usr/bin/su - pin -c "/home/pin/ok"