landog
April 28, 2011, 4:46pm
1
This has to be the ultimate newbie question...
I have a script that works well. To run it, I cut and paste it into a putty session.
Is there a way to put the script into a file and just run that file -- like a DOS batch file?
I'd like to schedule the file to run daily.
Thanks,
-dog
open a file in an editor: script.sh
place your commands there.
if you are going to run it in cron (scheduler) put these lines at the top of the file
#!/bin/bash <- forces the script to use bash otherwise you get /bin/sh whatever that is.
. /etc/profile
. /path/to/dog/home/.profile <- if you do not have .profile, skip it
close the file.
chmod \+x /path/to/my/script.sh <- makes the script executable.
crontab -e lets you enter a job for scheduling. Here is a cron tutorial:
Crontab � Quick Reference
5 23 1 * * /path/to/script.sh
will run the script at 11:05 every month on day one of the month, for example.
1 Like
Chirel
April 28, 2011, 5:04pm
3
Hi
Just cut and paste the script into a new file using vi or any other editor.
For example my_script
Then change the right so you can execute this file :
$ chmod +x my_file
And now you can run the script
$ ./my_script
To finish you have at least two choice to run this script daily.
Copy the script file to /etc/cron.daily (if you have the right to do it)
Launch : crontab -e to add a line like this
30 14 * * * /home/mylogin/myscript
This will launch the script everyday at 14:30
Edit: jim mcnamara was faster
1 Like