LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-11-2018, 11:46 PM   #1
shipon_97
Member
 
Registered: Oct 2005
Location: Bangladesh
Posts: 504

Rep: Reputation: 31
line execution in linux using crontab


Dear Friends ,

I try to execute below three lines as a script . Individually script is running fine but as a crontab , it is not working properly .

---------
cat ntp.sh
#!/bin/bash
service ntpd stop
sleep 5; /usr/sbin/ntpdate -s pool.ntp.org
sleep 5; service ntpd start
------------------------------

Using crontab, last two lines are executing fine but first line is not executing . Would anybody please help me regarding this ?
 
Old 02-11-2018, 11:53 PM   #2
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
To be honest, I'm not surprised your not seeing the output from the first line. CRON scripts run in the *background*, not the foreground.

And in addition, even if it did run in the foreground, unless it's a GUI based program, you still would not have a GUI window pop-up and display your ntp.sh file.

You have not said which Linux distribution you are talking about. So it's not easy to help without knowing that.

Edit: You have also got the 'shebang' (#!/bin/bash) line as the second line in your script, it HAS to be the first line.

Last edited by jsbjsb001; 02-11-2018 at 11:58 PM.
 
Old 02-11-2018, 11:57 PM   #3
shipon_97
Member
 
Registered: Oct 2005
Location: Bangladesh
Posts: 504

Original Poster
Rep: Reputation: 31
Thanks it is working now ...

#!/bin/bash
/etc/init.d/ntpd stop
sleep 5; /usr/sbin/ntpdate -s ntp.org
sleep 5; /etc/init.d/ntpd start
 
Old 02-12-2018, 04:28 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
Although your cron script problem has been solved there should be no reason if ntp is working correctly to force a time correction using ntpdate.
 
  


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
[SOLVED] issue with crontab job execution INDy2k Linux - Server 7 04-24-2014 01:38 AM
[SOLVED] Crontab: Cannot see entries, but execution running shivaa Solaris / OpenSolaris 11 02-18-2013 02:38 AM
crontab execution + log argie01 Linux - Software 7 01-03-2013 12:34 PM
[SOLVED] Thread Execution Line Question varoluscuprens Programming 1 05-03-2012 08:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:16 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