Operating System - HP-UX
1752680 Members
5709 Online
108789 Solutions
New Discussion юеВ

Re: how to configure cron

 
SOLVED
Go to solution
rustam_2
Super Advisor

Re: how to configure cron

Hi Jose,

I changed my script value
$vi rename.sh
mv my_file.log my_file_$(/usr/bin/date +%m%d%Y).log
checked script by running manually and it renamed my file. Then changed running time of cron task
$crontab -e
50 22 * * * /u02/script/rename.sh
it had to run my script at 22:50 but didnt :(

I noticed 1 line messages in log file about rename file:
> CMD: /u02/dump/rename.sh

there are some information which generates every 15 minutes during whole day last half year. dont know what is it. Dont you know what is it? Maybe this makes some barer?

> CMD: /opt/sfm/bin/restart_sfm.sh
> root 12270 c Mon Feb 21 22:05:00 WST 2011
> CMD: /etc/opt/resmon/lbin/mon_EMSHAProvider_state.sh
> root 12271 c Mon Feb 21 22:05:00 WST 2011
< root 12270 c Mon Feb 21 22:05:01 WST 2011
< root 12271 c Mon Feb 21 22:05:01 WST 2011
> CMD: /opt/sfm/bin/restart_sfm.sh
rustam_2
Super Advisor

Re: how to configure cron

Hi Jose,

I changed my script value
$vi rename.sh
mv my_file.log my_file_$(/usr/bin/date +%m%d%Y).log
checked script by running manually and it renamed my file. Then changed running time of cron task
$crontab -e
50 22 * * * /u02/script/rename.sh
it had to run my script at 22:50 but didnt :(

I noticed 1 line messages in log file about rename file:
> CMD: /u02/dump/rename.sh

there are some information which generates every 15 minutes during whole day last half year. dont know what is it. Dont you know what is it? Maybe this makes some barer?

> CMD: /opt/sfm/bin/restart_sfm.sh
> root 12270 c Mon Feb 21 22:05:00 WST 2011
> CMD: /etc/opt/resmon/lbin/mon_EMSHAProvider_state.sh
> root 12271 c Mon Feb 21 22:05:00 WST 2011
< root 12270 c Mon Feb 21 22:05:01 WST 2011
< root 12271 c Mon Feb 21 22:05:01 WST 2011
> CMD: /opt/sfm/bin/restart_sfm.sh

regards,
rustam
Dennis Handly
Acclaimed Contributor

Re: how to configure cron

>2. Opened crontab file with command

(On Unix systems you edit/view files, not open.)

>But my script did not run.

Add "set -x" to your script to trace execution.

>If script has problem logfile must have error information.

No, the stdout/stderr gets mailed to that user.

>My script includes this line
mv my_file.log my_file_$(date +%m%d%Y).log

That should work fine. You may have problems trying to do this more than once a day.

Also your script should start with:
#!/usr/bin/sh

>All users have privileges:
$ ls -l /u02/scripts/rename.sh
-rwxrwxrwx root sys /u02/scripts/rename.sh

This is a security hole. You shouldn't allow write access:
chmod go-w /u02/scripts/rename.sh

>Do you know what is it?
/opt/sfm/bin/restart_sfm.sh

These are part of System Fault Management. Leave it alone.

>Jose: As we have indicate you should include the full path for used commands

In this case mv and date are in the the default PATH.
Jose Mosquera
Honored Contributor

Re: how to configure cron

Hi Rustam,

Please ensure that you are inside of a "my_user" session, and at the system prompt executes the command with this trace option: sh -x /u02/script/rename.sh
What happened?

Now try to generate a cumulative trace file at the "crontab -e" session, then replace your current entry by:
50 22 * * * sh -x /u02/script/rename.sh|tee -a /tmp/rename.log
After run it please check te content of /tmp/rename.log file.

Rgds.
Jose Mosquera
Honored Contributor

Re: how to configure cron

Hi again,

Please ensure that actions above indicated always been done from a "my_user" session.

Rgds.
Dennis Handly
Acclaimed Contributor

Re: how to configure cron

>Jose: Now try to generate a cumulative trace file:
50 22 * * * sh -x /u02/script/rename.sh | tee -a /tmp/rename.log

No need to use tee. And you need to capture stderr:
50 22 * * * sh -x /u02/script/rename.sh >> /tmp/rename.log 2>&1
rustam_2
Super Advisor

Re: how to configure cron

Hi Dennis and Jose,

I add trace in crontab file
crontab -l
11 11 * * * sh -x/u02/scripts/rename.sh >> /tmp/rename.log 2>&1

script has this line:
mv my_file.log my_file_$(/usr/bin/date +%m%d%Y).log

I got rename.log file in /tmp directory.

The file includes this message:
-x/u02/scripts/rename.sh: A specified flag is not valid for this command.

So what is wrong? I guess something wrong in my rename.sh.

Regards,
rustam
Hakki Aydin Ucar
Honored Contributor

Re: how to configure cron

>mv my_file.log my_file_$(date +%m%d%Y).log

did you try it this way ;

/usr/bin/mv my_file.log my_file_$(/usr/bin/date +%m%d%Y).log
rustam_2
Super Advisor

Re: how to configure cron

Hi Hakki,

>>did you try it this way ;
>>/usr/bin/mv my_file.log my_file_$(/usr/bin/>>date +%m%d%Y).log

I tried and still have message in my /tmp/rename.log file

-x/u02/scripts/rename.sh: A specified flag is not valid for this command.

All syntaxes work correctly manually.
Hakki Aydin Ucar
Honored Contributor

Re: how to configure cron

try 1:
11 11 * * * /usr/bin/sh -x/u02/scripts/rename.sh >> /tmp/rename.log 2>&1

try 2:
chmod 755 /u02/scripts/rename.sh
11 11 * * * /u02/scripts/rename.sh >> /tmp/rename.log 2>&1