We help IT Professionals succeed at work.

Bash Scripts to run program

7,503 Views
Last Modified: 2008-01-09
Hi all I am tring to find or get help to wright bash script to run a program at night and the stop
I need the program to start running at 10pm and stop at 6am which i was going to run via cron I have never coded a bash script so i am lost here.

The program script lives in the home directory and needs to be excuted in directory it lives in
the program is web crawler it crawls UK sites only so I want to pass one command to the crawler between hours 10pm to 6am   then the it stops then i wnat to pass another command to the crawler between the hours 7am to 9pm. then set up with cron.

I have tried this with cron but it does not work
cd /home/user/program_dir/ ./myprogram -a -c test
Comment
Watch Question

Commented:
You can write bash scripts just like you would an MS-DOS batch file.  Simply put a #! on the first line, and bash will know it's a script.  Write however many you want with the commands you would normally just type in at the command line.  Then, add those scripts to cron.  It won't care that they're scripts and not binaries.
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2007
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2007

Commented:
Where I say "every half hour" above, I meant "every hour"

Author

Commented:
Tintin

Your's sounds what i am after a know about bash #! I need to run crawler every day starting from 10pm to 6am then stop the crawler but i don't just want to kill the crawler at 6am as it writes to mysql database and that would not be good i need just to issue stop command to to crawler so the crawler itself will stop and write all threads to the database before stopping.  Then issue another command at 7am to 9pm to the crawler to run am crawl which uses less threads and will not over web servers then stop this am crawl and start all over again every day?.

this what i have got so far with custom command
------------------
PM Crawl
./MYPROGRAM -i google.co.uk -u -l 100 -x & sleep 600 kill -0 $! && kill $!

AM Crawl with crawl delay of 1 second & only using 10 Treads
./MYPROGRAM -i google.co.uk -u -l 100 -x -d 1 -t 10 & sleep 600 kill -0 $! && kill $!

the 600 should = 10 Hours in seconds but the kill is killing all crawler threads instantly.

Many Thanks
Darren
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
10 hours is 36000 seconds
what is the stop command that you need to issue?

Author

Commented:
HI ozo

The command via key board is alt&c to stop the crawler then the crawler stops after all threads have finished?

Cheers
Darren
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
if you mean <control-c> that probably sends a kiil -2

Author

Commented:
Hi Sorry yes you are right ctrl&c ?

ozo me being idot some times would i put all this in bash script and then run script via cron or just put it in directly as cron job?

Does this look correct to you ozo

cron start crawler at 10pm every day
PM Crawl

 cd /home/user/crawler/; ./MYPROGRAM -i google.co.uk -u -l 100 -x & sleep 2800 kill -2 $! && kill $!

cron start crawler at 7am every day
AM Crawl with crawl delay of 1 second & only using 10 Treads

cd /home/user/crawler/; ./MYPROGRAM -i google.co.uk -u -l 100 -x -d 1 -t 10 & sleep 15400 kill -2 $! && kill $!

many thanks
Darren
CERTIFIED EXPERT
Top Expert 2007
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.