- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: how to configure cron
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2011 10:42 PM
02-20-2011 10:42 PM
I need to configure cron task for running several patches by turn.
I read documentation and now need some practical advices. Planning these steps:
1. I checked, does this service run or doesnt
$ps -ef |grep cron
root 1633 1 0 Oct 29 ? 0:18 /usr/sbin/cron
my_user 5535 20242 0 11:28:56 console 0:00 grep cron
so here is ok.
2. I checked, does my_user exist in cron.allow tab.
$cd cd /var/adm/cron
$less cron.allow
root
adm
uucp
so my_user doesnt exit here, should i add my user? is it ok if i add with vi?
3. My file rename.sh is in /u02/scripts/ and i manually run this script like this $./rename.sh
So how can i add command in crontab file using crontab -e? should i show my command so: /u02/scripts/./rename.sh? or it's wrong syntax? it is a bit complicated. So help me, please.
Regards,
Rustam
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2011 12:29 AM
02-21-2011 12:29 AM
SolutionYes, you must add your user "my_user" with vi editor. if you not be skilled with vi editor I suggest you make first a copy of cron.allow file.
#cp -p cron.allow cron.allow.bak
You also add an entry in your cron.allow with this:
#echo my_user >> cron.allow
For "crontab -e" command you must indicate de full path and filename, the file must be enough privileges for execution, in your case "/u02/scripts/rename.sh" is fine. The correct syntax of crontab command can be viewed:
#man crontab
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2011 12:54 AM
02-21-2011 12:54 AM
Re: how to configure cron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2011 02:57 AM
02-21-2011 02:57 AM
Re: how to configure cron
Right! which indicates Hakki is important, the cron does not load the definition of environment that normally a user loads when login to the system (/etc/profile, /etc/PATH, homedir user's profile, etc). Other way could be set and export PATH variable as Global enviroment definition, and any others specific variables requested as particular environment definitions (ORACLE_HOME, ORACLE_SID, etc). With these definitions you have search/execute capabilities for commands.
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2011 04:40 AM
02-21-2011 04:40 AM
Re: how to configure cron
I did following actions:
1.Add to cron.allow file my_user
#echo my_user >> cron.allow
2.Opened crontab file with command
$crontab â e and add this line
50 14 * * * /u02/scripts/rename.sh
For running my script at 14:50 everyday
3.$crontab â l shows me
50 14 * * * /u02/scripts/rename.sh
But my script did not run. I checked log file /var/adm/cron/log and found nothing according my script.
What is problem? Does not my user have some privileges to /var/spool/cron/crontabs/my_user file? Or as Hakki said my script has problem? If script has problem log file must have error information. I guess cron doesnt know something about my job.
My script includes this line
mv my_file.log my_file_$(date +%m%d%Y).log
Regards,
rustam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2011 04:47 AM
02-21-2011 04:47 AM
Re: how to configure cron
Have you tested your script at the prompt before try with the cron?
Have your script enough execution privilegues, please post us this command output:
#ls -l /u02/scripts/rename.sh
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2011 05:08 AM
02-21-2011 05:08 AM
Re: how to configure cron
$ ls -l /u02/scripts/rename.sh
-rwxrwxrwx 1 root sys 40 Feb 21 15:34 /u02/scripts/rename.sh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2011 05:17 AM
02-21-2011 05:17 AM
Re: how to configure cron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2011 07:24 AM
02-21-2011 07:24 AM
Re: how to configure cron
>>Could we see the contents of the script?
I gave at 12:40:42 GMT
>>My script includes this line
>>mv my_file.log my_file_$(date +%m%d%Y).log
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2011 07:36 AM
02-21-2011 07:36 AM
Re: how to configure cron
Ooops, is too simply!!! :)
Ok, I guess that directory where run this have enough privileges (execution/write).
Well, this looks a search/execution command path issue. As we have indicate you should include the full path for used commands, or set PATH variable to locate them.
A way to know the full path of a command is:
#whence date
A full path assigned in Global PATH variable will be reported.
Then replace:
date +%m%d%Y
By:
/fullpath/date +%m%d%Y
Please try this...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2011 10:12 AM
02-21-2011 10:12 AM
Re: how to configure cron
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2011 10:15 AM
02-21-2011 10:15 AM
Re: how to configure cron
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2011 11:22 AM
02-21-2011 11:22 AM
Re: how to configure cron
(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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2011 12:28 PM
02-21-2011 12:28 PM
Re: how to configure cron
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2011 12:37 PM
02-21-2011 12:37 PM
Re: how to configure cron
Please ensure that actions above indicated always been done from a "my_user" session.
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2011 12:38 PM
02-21-2011 12:38 PM
Re: how to configure cron
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2011 12:54 AM
02-22-2011 12:54 AM
Re: how to configure cron
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2011 01:10 AM
02-22-2011 01:10 AM
Re: how to configure cron
did you try it this way ;
/usr/bin/mv my_file.log my_file_$(/usr/bin/date +%m%d%Y).log
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2011 01:20 AM
02-22-2011 01:20 AM
Re: how to configure cron
>>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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2011 01:31 AM
02-22-2011 01:31 AM
Re: how to configure cron
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2011 02:22 AM
02-22-2011 02:22 AM
Re: how to configure cron
>>try 1:
>>11 11 * * * /usr/bin/sh -x/u02/scripts/>>rename.sh >> /tmp/rename.log 2>&1
it gave nothing new. In log file:
-x/u02/scripts/rename.sh: A specified flag is not valid for this command.
>>try 2:
>>chmod 755 /u02/scripts/rename.sh
>>11 11 * * * /u02/scripts/rename.sh >> /tmp/>>rename.log 2>&1
file didnt rename but in log file new event. Event about privileges
mv: my_file.log: cannot access: No such file or directory
crontab -l
15 15 * * * /u02/scripts/rename.sh >> /tmp/rename.log 2>&1
less rename.sh
/usr/bin/mv my_file.log my_file_$(/usr/bin/date +%m%d%Y).log
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2011 02:31 AM
02-22-2011 02:31 AM
Re: how to configure cron
I don't know if I had the same problem, but I've splited it, so you can try this:
#!/usr/bin/sh
DATUM='date +%m%d%Y'
mv my_file.log my_file_$DATUM.log
HTH
V.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2011 02:36 AM
02-22-2011 02:36 AM
Re: how to configure cron
Happens because you have a space omission among "sh -x" and /u02/scripts/rename.sh. Please ensure this one into "crontab -e" session:
11 11 * * * sh -x /u02/scripts/rename.sh >> /tmp/rename.log 2>&1
Would you matter changing the syntax of your script with this one? (the result is the same):
#!/usr/bin/sh
TIMESTAMP=`date +%m%d%Y`
WORKDIR=Please just indicates the full path where the "my_file.log" is placed.
cd $WORKDIR
mv my_file.log my_file_${TIMESTAMP}.log
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2011 03:05 AM
02-22-2011 03:05 AM
Re: how to configure cron
>/usr/bin/mv my_file.log my_file_$(/usr/bin/date +%m%d%Y).log
are you sure in yur file is on correct place ?
/usr/bin/mv /
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2011 04:50 AM
02-22-2011 04:50 AM
Re: how to configure cron
Now i have:
$crontab -l
32_17_*_*_*_/usr/bin/sh_-x/u02/scripts/rename.sh_>>_/tmp/rename.log 2>&1
_ means space between words
less rename.sh
/usr/bin/mv /u02/scripts/my_file.log /u03/export/my_file_$(/usr/bin/date +%m%d%Y).log
and checked this command line also:
/usr/bin/mv /u02/scripts/my_file.log my_file_$(/usr/bin/date +%m%d%Y).log
Still all various commands in rename.sh work correct manually.