LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking > Linux - Wireless Networking
User Name
Password
Linux - Wireless Networking This forum is for the discussion of wireless networking in Linux.

Notices


Reply
  Search this Thread
Old 02-21-2007, 03:09 AM   #1
Siva4Linux
Member
 
Registered: Sep 2006
Posts: 31
Blog Entries: 1

Rep: Reputation: 15
Executing commands at a specified time


Hello there,

I am carrying out some wireless testbed experiments and my testbed consists of 6 laptops. One of the conditions of the experiments is that I need to initiate the applications and protocols at the same time in each laptop. To suit this requirement, I am wondering as to how I can write a simple script to specify that the follwing applications need to begin exactly at (say) 13:15.

run application1 and application2 at 13:15

Thanks in advance for taking your invaluable time to answer my question.

Best Regards,

Siva

Last edited by Siva4Linux; 02-21-2007 at 03:11 AM.
 
Old 02-21-2007, 03:18 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by Siva4Linux
One of the conditions of the experiments is that I need to initiate the applications and protocols at the same time in each laptop.
First of all you have to syncronize all the laptops against a NTP server to be sure that the system time is the same for all. Second you can run an application at a specified time by means of cron. This implies:
1) the crond (cron daemon) must be running on all the laptops
2) you have to allow the execution of cron jobs on a user basis
3) you have to write a proper crontab, e.g.
Code:
15 13 * * * /some/dir/application1
See man cron & man -S5 crontab for details. If the applications are to be run only once, you may consider the at command as well (this can also be launched from a shell script)

Last edited by colucix; 02-21-2007 at 03:41 AM.
 
Old 02-21-2007, 03:43 AM   #3
Siva4Linux
Member
 
Registered: Sep 2006
Posts: 31

Original Poster
Blog Entries: 1

Rep: Reputation: 15
Hello Colucix,

Thanks for your quick response. Given that my applications need to be run exactly at once, I thought of using "at" and tried the follwing:

at -V -f <runMyApplication-script> -mv 5.52

runMyApplication is a script that calls all my applications. When I tried to use the above, nothing seemed to happen. I wasn't sure whether the jobs were running in the back-ground ??? Do you have an idea as to why I couldn't see anything on the console when I tried to use the above "at" utility ???

Thanks and Regards,

Siva
 
Old 02-21-2007, 03:58 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Of course there is a little syntax error on the command line you have posted, or better there is no indication about the time at which execute the application. A correct way to use at is, e.g.
Code:
at now +3 hours
at> date > /home/user/testfile
at> <EOT>
You see you have to type a TIME specification (now + 3 hours) and then the command(s) to execute. This is an interactive usage of at, in the sense you have to type commands at the at> prompt and terminate input by typing Ctrl-D.
The alternative is the one you have just seen, that is option -f to execute command written in a file:
Code:
at 13:15 -f script_to_run -m
See man at for a correct form of the TIME specification. Just an hint: the option -V simply output the version of the at software, the -v simply print the TIME specification on the terminal in the date command format. They are quite unuseful in your experiment.

Last edited by colucix; 02-21-2007 at 04:00 AM.
 
Old 02-21-2007, 04:21 AM   #5
Siva4Linux
Member
 
Registered: Sep 2006
Posts: 31

Original Poster
Blog Entries: 1

Rep: Reputation: 15
Hello Colucix,

I tried in the way you suggested and it works fine. But the problem is that the processes run in the background. Given that I need to monitor the console for the output of my running applications, the use of "at" would not be any use, unless I find a mechanism to redirect the output to a file and read it using "watch". The other option is to write my own script that does the work for me without using "at". Do you have an idea as to how I can write a simple script that can be a substitute to "at"

Thanks in advance.

Regards

Siva
 
Old 02-21-2007, 04:35 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
unless I find a mechanism to redirect the output to a file and read it using "watch"
Your idea is good, you can redirect the standard output together with the standard error in a file. During the execution you can see the progression of the file using
Code:
tail -f file.log
pressing Ctrl-C to interrupt the tail command.
Quote:
The other option is to write my own script that does the work for me without using "at". Do you have an idea as to how I can write a simple script that can be a substitute to "at"
Sincerely I have no idea, at and cron are the only ways to run a program at a specified (delayed) time. Writing such a script could result in writing the source code of the at command! By the way a dirty way to do this in a bash script, could be
Code:
#!/bin/bash
while [ `date +%H%M` -ne 1133 ] ; do
     sleep 5
     echo "still waiting..."
done
Please note the reversed single quotes around the date command. The code above query the output of the date command, waiting for a specific hour and minute (11:33 in my example) with a timestep of 5 seconds (sleep 5) between each query. When the hour and minute is reached the while loop is terminated and you can put the commands to execute after and outside the loop itself.
 
Old 02-21-2007, 05:43 AM   #7
Siva4Linux
Member
 
Registered: Sep 2006
Posts: 31

Original Poster
Blog Entries: 1

Rep: Reputation: 15
Hello Colucix,

Thanks for your time !, your script works for me.

Cheers

Siva
 
Old 02-21-2007, 05:49 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You are welcome!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
using sleep() and time() commands together in c++ totaljj Programming 1 02-14-2007 07:12 AM
can ssh execute multiple commands at the same time? Singist Linux - Networking 2 04-04-2006 09:14 AM
Commands executed at boot time Johnburrell Linux From Scratch 3 09-18-2005 01:56 PM
c program that executes during a certain amount of time jagman Programming 6 04-13-2005 09:22 AM
Time commands from command line ToothlessRebel Linux - Newbie 1 03-09-2005 10:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking > Linux - Wireless Networking

All times are GMT -5. The time now is 02:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration