LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-09-2015, 11:13 AM   #1
k4elo
LQ Newbie
 
Registered: Dec 2014
Posts: 4

Rep: Reputation: Disabled
script runs from command line but fails as a cron job


Another script that runs ok from command line but fails as a cron job.

Code:
#!/bin/bash -l

# this script checks to see if the "node bnlserver.js" program is running
# and restarts it if not

if ! ps -ef | grep -q "[b]nlserver[.]js"; then
    node bnlserver.js
fi
The script and node and bnlserver.js are all in /home/k4elo/bin
The cron job setup was /home/k4elo/bin/restart_node_server.sh

The cron job executes the script and it errors saying node - no such file or directory
Tried putting in
Code:
PATH = $PATH:/home/k4elo/bin
But that errors with PATH - no such command

Any help greatly appreciated.
 
Old 01-09-2015, 11:35 AM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by k4elo View Post
Code:
PATH = $PATH:/home/k4elo/bin
Try
Code:
PATH=$PATH:/home/k4elo/bin
 
1 members found this post helpful.
Old 01-09-2015, 11:43 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
looks like you need to cd into /home/k4elo/bin in that script or use full path:
/home/k4elo/bin/node /home/k4elo/bin/bnlserver.js
why do you need -l in the first line (bash -l ??)
 
1 members found this post helpful.
Old 01-09-2015, 12:10 PM   #4
k4elo
LQ Newbie
 
Registered: Dec 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks for finding my mistake Habitual. Working now.

pan64 - some other guru responding to someone else with a similar problem to mine said it should pick up the path - obviously not in my case.

Thanks guys!
 
Old 01-09-2015, 12:51 PM   #5
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Glad it worked out!
 
  


Reply

Tags
cron, script



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
TCL script runs fine manually but not as a cron job vsandilya Programming 2 10-22-2012 10:13 AM
[SOLVED] perl script runs fine from command line but fails when invoked by nagios andrest964 Linux - Newbie 7 10-04-2012 09:04 AM
Bash script works from command line, fails from cron cmfarley19 Linux - General 4 08-14-2009 12:24 PM
Script runs fine from command line, but not when attempted from Cron hwest Linux - Newbie 8 12-11-2008 06:48 PM
script runs fine from a command line, but doesn't work from cron? kleptophobiac Linux - Software 5 05-03-2004 04:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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