LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-26-2006, 03:13 AM   #1
rockarolla
LQ Newbie
 
Registered: Dec 2006
Distribution: Fedora 9
Posts: 28

Rep: Reputation: 15
shell script timing


Hi,

how can we run a given shell script or application at a given time, say once or periodically?

thanks!
 
Old 12-26-2006, 03:23 AM   #2
penguiniator
Member
 
Registered: Feb 2004
Location: Olympia, WA
Distribution: SolydK
Posts: 442
Blog Entries: 3

Rep: Reputation: 60
To run it once use the at command. You must ensure that the at daemon is running. Then you can type something like:

at 4:07pm
warning: commands will be executed using /bin/sh
at> command to run
at> another command to run
at> Ctrl+d
job 1 at 2006-12-26 04:07
$

You can place this in a script to make it reschedule itself like this, perhaps using calculated times based on runtime conditions:

at $time 2>/dev/null << EOF
command to run
another command to run
EOF

You can also use cron to create a regular schedule for the program.
 
Old 12-30-2006, 01:29 AM   #3
leo.zhai
LQ Newbie
 
Registered: Dec 2006
Posts: 1

Rep: Reputation: 0
You can use "crontab -e" to edit a regular schedule and use "crontab -l" to display your schedule.
 
Old 01-01-2007, 08:46 AM   #4
rockarolla
LQ Newbie
 
Registered: Dec 2006
Distribution: Fedora 9
Posts: 28

Original Poster
Rep: Reputation: 15
actually what I need is to listen to a given process or event that is due to certain circumstances my desktop is connected via a linksys usb adapter WUSB54G but the connection is not stable and from time to time its disconnected. I need to reconnect manually or as I did using the cron facility, However the latter cannot add a modprobe as I think the path is not correct. The disadvantage cron has is that even if the connection isn't broken it will periodically run the commands (like ifconfig wlan0 etc...) I think it is possible to make it better by adding a line in the /etc/inittab file for example using respawn when the connection is lost ld you suggest a better way?

thanx,
 
Old 01-06-2007, 06:11 AM   #5
FredrikN
Member
 
Registered: Nov 2001
Location: Sweden
Distribution: GNU/Linux since -97
Posts: 149

Rep: Reputation: 15
Well, of of many ways is to create a script that autostarts everytime the systems turns on.


PHP Code:
#!/bin/sh

Create an array of ten sites or more.
ARRAY=(
  
site1
  site2
  
.. 
  ..
  ..
}

while [ 
true ]
do 
   
Select a random site.
   
RANGE=${#ARRAY[*]}
   
number=$RANDOM
   let 
"number %= $RANGE"

   
if [ `wget -O /tmp/trash.html ${ARRAY[$number]}` == TIMEOUT ]
   
then 
       create a 
new connection
   fi

sleep 60
;

done

Or if you want to check if some process is alive

PHP Code:
#!/bin/bash

while [ true ]
do

 if [ 
"`ps aux | grep your_proc | grep -v grep`" == "" ]
 
then
    
echo 'Not alive, create connection or run some command'
 
fi

sleep 60
;

done

Last edited by FredrikN; 01-06-2007 at 06:51 AM.
 
  


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
Script help for awk and timing commands jakev383 Linux - General 2 12-18-2006 07:35 PM
how to start timing and print the timing result on portions of java codes ?? alred Programming 2 05-15-2006 10:00 AM
I made a shortcut to a shell script and it is using default shell icon... shlinux Linux - Software 2 04-20-2006 06:29 AM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 02:34 PM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:54 PM.

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