Asked By
sahara
0 points
N/A
Posted on - 09/28/2011
Dear All,
A complex situation has occurred in my working environment.
My organization use two servers for different applications, one server is windows 2008, and the other server is on UNIX.
I work most of the times with the win 2008 server, and due to frequent travels I am allowed to access this server via Remote desktop connection, through my laptop which is on win 7, within our corporate secure wan.
Recently due to some emergency, I have to access the unit system too remotely, and for this purpose I use the TELNET option.
It is required by me to run some batch commands on both the systems, and for windows 2008 system, I have been able to automate this batch command to run on a scheduled time without my manually executing the same.
However, I am still unable to automate the running of a script on the UNIX system, and have to manually telnet and then run the script, which is sometimes risky in case I forget to run on the prescribed time.
I am not a good programmer, and have developed the batch on windows with the help of some friends.
They are also not able to help me in the case of UNIX systems.
Please tell me if it is possible to run this script automatically, without doing ant internal programming on the server itself? is there some tool which can be used?
Sahara
Answered By
David1
0 points
N/A
#83358
HOW TO AUTOMATICALLY RUN A SCRIPT ON UNIX SYSTEM
In Linux, several ways can allow you to automate the execution of your script, but the system cron is the best option, and that's what are running to in this explanation.
Cron can automate the execution of scheduled commands, and this is how you do it :
Considering that your script is automate_script.sh, this script is assumed to be in your user David home folder (/home/david), and of course with execution permission otherwise you need first to give the execution permission, with the following command :
-
$sudo chmod u+x automate_script.sh
Supposing that you need to execute the script once a day at 8 am, if not you can still follow the same concept to do what ever you want;Â for the record:
The time line within the cron system is as follow :
-
Minute(from 0 to 59) Hour (0-23) Day_month(1-31) month(1-12) Day_week(0-6).
NOTE : for the day_week entry , Sunday is being 0.
When ever to you want to set an entry within your system, give it a value otherwise, give it an '*'.
Now to set cron to schedule our script we need to edit the cron entry via the crontab command-line, with -e flag set on.
So echo the command:
This will prompt you to choose a text editor, so choose your favorite. Add a new cron entry for script to be executed at the time you want. For our example, the entry would be:
-
* 8 * * * ~/automate_script.sh
This will allow you execute you script every day at 8 am, and that's it,hope this is helping.
Thanks!!