LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 06-17-2016, 11:44 AM   #1
wildbi111
LQ Newbie
 
Registered: Jun 2016
Posts: 2

Rep: Reputation: Disabled
Bash Script Issue


Hello - I've run into an odd little scripting problem where if I run the script from the command line it works fine and adds two at jobs. But when run from the crontab it only creates the sunrise job. I had both working (see original sunset line) until I wanted to make the sunset job run 15 minutes before sunset. I'm using this to turn house lights on/off and am using Dan Risacher's sunwait program (http://www.risacher.org/sunwait/). Any suggestions would be appreciated.

Bill Richards
-------------------- script ----------------------
#!/bin/bash

# original line to calculate sunset
#sunset=`/usr/local/bin/sunwait -p 35.41N 97.35W |/bin/grep "Sun rises"|/usr/bin/cut -d" " -f25`

# line to calculate 15 minutes before sunset
sunset=$((`sunwait -p 35.41N 97.35W |grep "Sun rises"|cut -d" " -f25` - 15))

# line to calculate sunrise
sunrise=`/usr/local/bin/sunwait -p 35.41N 97.35W |/bin/grep "Sun rises"|/usr/bin/cut -d" " -f22`

# create at jobs
/usr/bin/at -f /usr/local/bin/morning-off.sh $sunrise
/usr/bin/at -f /usr/local/bin/night-on.sh $sunset
 
Old 06-17-2016, 12:06 PM   #2
hazel
Senior Member
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware, OpenBSD
Posts: 4,190
Blog Entries: 11

Rep: Reputation: 2368Reputation: 2368Reputation: 2368Reputation: 2368Reputation: 2368Reputation: 2368Reputation: 2368Reputation: 2368Reputation: 2368Reputation: 2368Reputation: 2368
You haven't given the full path for the sunwait command in your sunset job. Cron jobs need paths for all their commands; there doesn't seem to be a $PATH variable for them.
 
Old 06-17-2016, 12:08 PM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,230

Rep: Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724
Look at what works and what doesn't work, see any difference in syntax in that line:
Code:
# line to calculate 15 minutes before sunset
sunset=$((`sunwait -p 35.41N 97.35W |grep "Sun rises"|cut -d" " -f25` - 15))
 
Old 06-17-2016, 12:43 PM   #4
wildbi111
LQ Newbie
 
Registered: Jun 2016
Posts: 2

Original Poster
Rep: Reputation: Disabled
Talking That was it...

Hazel - Thanks! Somehow you can look at something over and over again and just miss the simplest thing. I appreciate your keen eyes!

Bill
 
Old 06-17-2016, 01:04 PM   #5
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,575
Blog Entries: 3

Rep: Reputation: 2296Reputation: 2296Reputation: 2296Reputation: 2296Reputation: 2296Reputation: 2296Reputation: 2296Reputation: 2296Reputation: 2296Reputation: 2296Reputation: 2296
I'd also check the backticks ( ` ) and see if they can be removed. Usually $( ... ) will handle command substitution. So I'm not sure what there is to gain by nesting the backticks inside $( ... ) and would leave the backticks out.

Edit: example:
Code:
 sunset=$(sunwait -p 35.41N 97.35W |grep "Sun rises"|cut -d" " -f25 - 15)

Last edited by Turbocapitalist; 06-17-2016 at 01:07 PM.
 
Old 06-17-2016, 02:22 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,774

Rep: Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054Reputation: 3054
As the command line only differs slightly I would also suggest it could be limited to a single line to perhaps produce 2 items in an array. If you were to show the output of your sunwait command we may have
an alternative
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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] Bash script issue kingston Linux - Newbie 10 10-07-2015 08:04 AM
Cygwin issue with bash script jdwilder Other *NIX 7 09-20-2013 05:53 AM
Bash script issue tibix00 Programming 22 07-21-2011 12:23 PM
Bash script debugging issue internetSurfer Programming 4 01-28-2008 08:24 PM
small bash script issue zoomzoom Linux - General 7 06-08-2004 06:33 PM

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

All times are GMT -5. The time now is 05:53 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration