- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- scheduling a shell script
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
01-17-2006 03:41 AM
01-17-2006 03:41 AM
i want to schedule a shell script jasmine.sh to execute every day at a particular time but don't want to put it in cron job. i want to execute as a login account on mine i.e. as a non-root user.
how can i achieve this ?
thanks,
shiv
Solved! Go to Solution.
- Tags:
- crontab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2006 03:46 AM
01-17-2006 03:46 AM
SolutionDear Shiv,
you can add the entry in the crontab, ( in the command field)
su -
now, in the sheduled intervals , the script will be executed as the
With Regards,
Siva.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2006 03:47 AM
01-17-2006 03:47 AM
Re: scheduling a shell script
echo "/full_path/script.sh" | at 0200 tomorrow
Just add that line to the end of your script and it will repeat every day.
Pete
Pete
- Tags:
- AT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2006 03:55 AM
01-17-2006 03:55 AM
Re: scheduling a shell script
First the user must be allowed to use cron. Add the user to /var/adm/cron/cron.allow
Then the user can edit his/her crontab with the 'crontab -e' command. Or root can edit another users crontab via 'crontab -e username'.
When the jobs run they will be run as that user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2006 05:44 AM
01-17-2006 05:44 AM
Re: scheduling a shell script
The use of echo "/$PATH/filename" | at
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2006 05:49 AM
01-17-2006 05:49 AM
Re: scheduling a shell script
let sysadm add your name to at.allow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2006 05:57 AM
01-17-2006 05:57 AM
Re: scheduling a shell script
I use HP SIM to login and run commands for me regularly, and it has a 'run now' option, and a 'schedule' option.
Short of running cron or some other scheduler, this is likely your best (free) bet. SIM is normally used for monitoring, but I use it for sysadmin tasks much more than monitoring.
Hope it helps
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2006 03:04 PM
01-17-2006 03:04 PM
Re: scheduling a shell script
"at" is the command to help you.
http://docs.hp.com/en/B2355-60127/at.1.html
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2006 03:22 PM
01-17-2006 03:22 PM
Re: scheduling a shell script
i usually prefer:
20 09 * * * echo "/prod/myscripts/jasmine.sh"|su - shiv 1>/prod/script/logfiles/output-jasmine.crn 2>/prod/script/logfiles/error-jasmine.crn
using cron of course
hope this helps!
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2006 03:41 PM
01-17-2006 03:41 PM
Re: scheduling a shell script
you can use both "at" and cron jobs to do it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2006 05:32 PM
01-17-2006 05:32 PM
Re: scheduling a shell script
The best way although for executing the repeated jobs at a particular time is cron only. But as you already mentioned of asking the options apart from cron, a loop will be another option.
at will work but it will only process the job only once and for rescheduleing either you reschedule it again or put the rescheduling option is the script itself.
A loop will also achive the same function as you can sleep the loop for a particular time.
The loop file shall contain
#!/bin/sh
while true
do
/path/script
sleep 86400
done
The script should be executed at the right time initially, if not manually possible then use at for first use. Also you will require to restart it at every reboot.
HTH,
Devender
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2006 08:43 PM
01-17-2006 08:43 PM
Re: scheduling a shell script
you can sue 'at' command or if you have an Oracle instance you can use the dbms_jobs package.
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2006 03:26 AM
01-18-2006 03:26 AM
Re: scheduling a shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2006 03:28 AM
01-18-2006 03:28 AM
Re: scheduling a shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2006 03:28 AM
01-18-2006 03:28 AM
Re: scheduling a shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2006 09:06 AM
01-18-2006 09:06 AM
Re: scheduling a shell script
All it has to do is fail to finish the script once for any reason and its not scheduled any more. On the same note, all it has to do is get run one extra time manually and suddenly its scheduled twice.
Based on your original request I would recommend using cron for that user instead of the root cron.
H
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2006 05:17 PM
01-18-2006 05:17 PM
Re: scheduling a shell script
sleep 86400 will repeat the process after that manu seconds.
Caution - After every execution the time will be reduced by one second and obviously after 30 days in sequence you will find that the command is actually executing 30 sec. prior to the time set.
HTH,
Devender
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2006 05:25 PM
01-18-2006 05:25 PM
Re: scheduling a shell script
sleep 86400 will execute a script after 24 hrs exactly comleting the first run.
http://unix.derkeiler.com/Mailing-Lists/HP-UX-Admin/2004-09/0038.html
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2006 09:21 AM
01-21-2006 09:21 AM
Re: scheduling a shell script
I put the below line at the end of the script shiv.sh
echo "/home/sksonkar/shiv.sh"|at 0200 tomorrow
how does the shiv.sh script gets invoked at 2am tomorrow; because the line is at the end of the sript shiv.sh ?
Regards,
Shiv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2006 10:18 AM
01-21-2006 10:18 AM
Re: scheduling a shell script
You asked if you do:
# echo "/home/sksonkar/shiv.sh"|at 0200 tomorrow
"How does the shiv.sh script gets invoked at 2am tomorrow?"
This is just another way of specifying the filename that you want 'at' to run. The STDIN file descriptor (usually your terminal) is what is being read by 'at'. You can shorten this to:
# /home/sksonkar/shiv.sh|at 0200 tomorrow
... or write equivalent specifications for starting your script tomorrow (January 22 at 0200):
# at -f /home/sksonkar/shiv.sh 0200 tomorrow
# at -t 01220200 -f /home/sksonkar/shiv.sh
Have a look at the manpages for 'at' for more information.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2006 03:37 AM
01-22-2006 03:37 AM
Re: scheduling a shell script
I had scheduled the job home/sksonkar/shiv.sh|at 0200 tomorrow
it exexuted successfully today morning.
I believe it will not execute continuously tomorrow and day after.
For making it to run continuoulsy do i need to put the at command in the script shiv.sh and run "shiv.sh &" or run with the command "nohup shiv.sh" as a background process ?
Is there a command to view the details of the jobs scheduled via at command ?
Thanks,
Shiv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2006 03:56 AM
01-22-2006 03:56 AM
Re: scheduling a shell script
No, the script will not automatically execute again as setup.
One crude way to make continuous execution happen, as already noted, would be to place the body of your script's instructions in a loop that once executed, sleeps for 86,400 seconds. The drawback, of course, is that if your script ever fails, it's done until you manually intervene.
Another way to cause successive runs would be to use 'at' as you have, and add, as the *last* instruction for your script to re-schedule itself:
# at -f /home/sksonkar/shiv.sh now + 1 days
See the manpages for 'at' for more options!
Lastly, if you want to run a task with regularity, you should 'cron' it. This is what 'cron' is designed to do. You can run a process every day, many times a day, only on selected days of the week, etc. etc.
Please consult the 'crontab' manpages. For example, to run your script every 24-hours you would create a crontab entry (using the user account you want to use) like:
30 2 * * * /home/sksonkar/shiv.sh
This would run your script every day at 02:30
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2006 04:04 AM
01-22-2006 04:04 AM
Re: scheduling a shell script
Oh, I forgot to answer your last question.
To see tasks (if any) that have been scheduled via 'at', login as the user that scheduled them and do:
# at -l
To remove one, use:
# at -r
...with the job-id seen in 'at -l'. For instance:
# at -l
job 1138035079.a at Mon Jan 23 11:51:19 2006
# at -r 1138035079.a
Since you will ask, (good!) I'll tell you ahead of time that the jobid, here "1138035079" is the Unix epoch time --- the number of seconds since January 1, 1970. The jobid of 'at' is "translated" in the output. That is, "1138035079" is your localtime as shown: Mon Jan 23 11:51:19 2006.
Regards!
...JRF...