- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- crontab - script is not running
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
11-08-2008 08:07 AM
11-08-2008 08:07 AM
I need to run a script in crontab.If iam running the script manually it is running perfectly.Through crontab its not running.the script is rebooting the sever for a particular day:eg.
---------------------
#!/sbin/sh
DAYOFWEEK=`/usr/bin/date +%u`
DATE=`/usr/bin/date +%d`
if [ ${DAYOFWEEK} -eq "6" ] && [ ${DATE} -lt '9' ]
then
echo "rebooting server"
/usr/bin/cd /
/sbin/shutdown -r now
fi
--------------------
The crontab entry I don is:
# crontab -l
24 * * * * /test.sh
==========================
its not at all running.I checked with other comands like
55 * * * * /sbin/reboot
----------------------------is working perfectly.Could you pls suggest?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2008 11:33 AM
11-08-2008 11:33 AM
Re: crontab - script is not running
What about the file permission.?
Copy the script to /usr/bin and give necessary permission and try.
As per crontab entry script will run on 24th min of each hr ,Sat , when date is < 9.
Correct if I m wrong.
Thanks
Sen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2008 01:22 PM
11-08-2008 01:22 PM
Re: crontab - script is not running
1. File permission (execute permission).
2. Path of the script (specify the complete path), from your example the file should be located in root (/).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2008 06:56 PM
11-08-2008 06:56 PM
Re: crontab - script is not running
direct specify the command in the crontab for root will do the Job for us.
Example :-
55 * * * * /usr/sbin/shutdown -ry 0
or,
Check your file permission of the script.?
Thanks,
Johnson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2008 08:22 PM
11-08-2008 08:22 PM
Re: crontab - script is not running
I don't see how?
DAYOFWEEK=$(date +%w)
DATE=$(date +%d)
if [ ${DAYOFWEEK} -eq 6 -a ${DATE} -lt 9 ]; then
echo "rebooting server"
cd /
/sbin/shutdown -r now
fi
There was no need for /usr/bin in your paths. Your "if" syntax was wrong. And you must NOT use anything but a shell builtin for cd.
Note if this is used by crontab, there isn't any reason to check for both day of week and day of month. One can be done in crontab but you may want the script to run manually.
I also switched to %w so it matches crontab's numbering.
As Sen mentioned, you need to specify the hour of the day, this is Saturday at 0024:
24 00 * * 6 /test.sh
But the real question is, why do you want to reboot your server?
>Johnson: easier and simple way, directly specify the command
This doesn't meet the AND criteria.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2008 11:53 PM
11-09-2008 11:53 PM
Re: crontab - script is not running
leaving the invalid test expression beside,
it is rarely advised to use
/usr/bin/cd otherdir
This form is mainly available for some compatibility reasons only: creating a new process for a command, the change of the directory will be valid only during the runtime of this process. That may be intersting for testing purposes.
Always use a simple
cd otherdir
if you really want to do a 'change directory'.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2008 12:59 AM
11-10-2008 12:59 AM
Re: crontab - script is not running
One question:
Where is your PATH variable.
crontab runs scripts with no environment in cron. No PATH no finding binaries.
Most common cause of problems.
The crontab entry /test.sh requires the script to be in the root directory. Bad sysadmin practice.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2008 01:38 AM
11-10-2008 01:38 AM
Re: crontab - script is not running
thanks for your reply.
the script is having executive permission [777].
It is located in / only.
The script its self is running fine.
when iam putting in cron its not running.
My requirement is to reboot server on every particular day of the week for 3 months.
so i cant give /sbin/reboot.
Thanks
Sreekumar.r
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2008 02:56 AM
11-10-2008 02:56 AM
SolutionHave you tried my specific changes?
>Peter: it is rarely advised to use /usr/bin/cd
I would state this far stronger. Never use /usr/bin/cd. :-)
This is only for standards compliance, useless for ordinary users. cd(1) states one use, to check the exit status for directory accessibility.
>SEP: crontab runs scripts with no environment in cron.
crontab(1) sets PATH to: PATH=/usr/bin:/usr/sbin:.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2008 05:19 AM
11-10-2008 05:19 AM
Re: crontab - script is not running
To high-light Dennis's comment regarding 'cd' versus '/usr/bin/cd', simply compare:
# cd /var && pwd
/var
# pwd
# /usr/bin/cd /tmp && pwd
/var
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2008 05:58 AM
11-10-2008 05:58 AM
Re: crontab - script is not running
check the /var/adm/cron/log for information of how the script was executed.
Check also the mail to the root user ( which I assume you are using).
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2008 06:25 AM
11-10-2008 06:25 AM
Re: crontab - script is not running
Thanls for your reply.
Hello Dennis thanks alot.
It worked I removed the path entry [ /usr/bin/cd /]
from crontab.Now its working fine.
rgds Sreekumar.R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2008 08:24 AM
11-10-2008 08:24 AM
Re: crontab - script is not running
Please change those permissions. With 777 permissions, anyone who wants to can take control of your box as of the next saturday.
Since they can write to the file, all they have to do is add:
cp /bin/ksh /tmp/give_me_root
chown root:sys /tmp/give_me_root
chmod 1755 /tmp/give_me_root
Then, wait for the nexst reboot to execute it.
Doug
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2008 06:16 AM
11-11-2008 06:16 AM
Re: crontab - script is not running
ThanKs for your reply.
It worked I removed the path entry [ /usr/bin/cd /]
from crontab.Now its working fine.
rgds Sreekumar.R