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 05-24-2015, 02:21 PM   #1
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Rep: Reputation: 46
Grrr, code works on laptop but not netbook


Ladies & Gents,

I am having some issues trying to fill some variables from a csv file. The code works correctly on my laptop but when I run it on the netbook it does not fill the variables. As normal I am about 8 hours into this now and not getting anywhere. This is bash.

The code:
Code:
  OLDIFS=$IFS
  IFS=,
  [ ! -f $STORDIR/ShabbatData ] && { echo "$STORDIR/ShabbatData file not found"; exit 99; }
  while read CITY STATE ZIP LONG LAT TZ RTIME URL STATION SRTIME
  do
	echo "$CITY"
  done < $STORDIR/ShabbatData
  IFS=$OLDIFS
  
echo "The long $LONG"
echo "the lat $LAT"
echo "Time zone $TZ"
The debug from the laptop:
Code:
+ OLDIFS=' 	
'
+ IFS=,
+ '[' '!' -f /home/kingbee/bin/shabbat/data/ShabbatData ']'
+ read CITY STATE ZIP LONG LAT TZ RTIME URL STATION SRTIME
+ IFS=' 	
'
+ echo 'The long -**.****'
The long -**.****
+ echo 'the lat **.****'
the lat **.****
+ echo 'Time zone -4'
Time zone -4
And the debug from the netbook:
Code:
+ OLDIFS=' 	
'
+ IFS=,
+ '[' '!' -f /home/rbees/bin/shabbat/data/ShabbatData ']'
+ read CITY STATE ZIP LONG LAT TZ RTIME URL STATION SRTIME
+ echo ******
******
+ read CITY STATE ZIP LONG LAT TZ RTIME URL STATION SRTIME
+ IFS=' 	
'
+ echo 'The long '
The long 
+ echo 'the lat '
the lat 
+ echo 'Time zone '
Time zone
Both machines run Debian Testing and are patched regularly. Other than speed, and installed software, the only difference is the laptop is 64 and the netbook is 32. I did have some issues with the netbook not having gawk awhile back but after installing it that issue went away.

Is there any other software that could cause this issue if it was not installed?

Other wise the 800 line script works fine on both. Just wanting to get rid of the hard coded variables.

Thanks

Last edited by rbees; 05-24-2015 at 02:23 PM.
 
Old 05-24-2015, 05:06 PM   #2
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Hello,
my first question would be: Are you sure the input files ($STORDIR/ShabbatData) are identical on both machines? (Check with md5sum or od)
Can you show a sample of your input file? How many lines does it have?

My guess would be that the file on your netbook ends with a newline character, while the one on the laptop does not.

I'll start with the second example (the netbook), which is the correct behaviour, by the way:
read processes lines from the input file, one by one, setting the variables for every line, until it reaches end of file.
When it reaches eof, it attempts to read, but fails. It doesn't get any data, so the variables will be empty. It returns non-zero return code, so the loop terminates.

Now, for the other example (the laptop):
read processes each line as before, until itgets to the last line, which in this case does not end with '\n'. In other words, it reaches end of file before it finds the delimiter terminating the line.
In this case, read will get the data from the last line and set the variables, but will fail with a non-zero return code and the loop will terminate (i.e it will not run for the last line, as you can see in the output from set -xv)
 
Old 05-24-2015, 05:47 PM   #3
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
Thanks millgates,

It seams that there was something wrong with the csv. I scp the one of the laptop to the netbook and now it works. I had looked at that file several times for errors but could see none, so I don't know what was wrong with it. The md5sum's did not match up.

The csv is not suppose to have a blank line as per the example I was working from.

On another note I don't seam to be able to get the script to call it's self for the next weeks run. It creates the at job ok but it does not execute.
Code:
631     Sun May 31 00:00:00 2015 a rbees
JOB 631
#!/bin/sh
# atrun uid=1000 gid=1000
# mail rbees 0
***** deleted lots of lines ****************
cd /home/rbees/bin/shabbat || {
	 echo 'Execution directory inaccessible' >&2
	 exit 1
}
/home/rbees/bin/shabbat/NewCandleTime
the path to the script is set correctly and it is executable.

Code:
# Schedule run for next week
echo "$BINDIR/NewCandleTime" | at midnight next sunday
And I have tried
Code:
# Schedule run for next week
at midnight next sunday -f $BINDIR/NewCandleTime
and neither have worked. I didn't really want to use a cron job.
 
Old 05-25-2015, 02:29 AM   #4
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by rbees View Post
It seams that there was something wrong with the csv. I scp the one of the laptop to the netbook and now it works. I had looked at that file several times for errors but could see none, so I don't know what was wrong with it. The md5sum's did not match up.

The csv is not suppose to have a blank line as per the example I was working from.
In unix, by convention each line should be terminated with a '\n'. The presence of a '\n' at the end of the file does not mean there's a blank line. In vim, for instance, you will not see the difference. If you save a file with vim, it will put a newline after the last line by default. Some editors don't do that.

Quote:
Originally Posted by rbees View Post
On another note I don't seam to be able to get the script to call it's self for the next weeks run. It creates the at job ok but it does not execute.
the path to the script is set correctly and it is executable.
Try redirecting the output of the job into a file

Code:
echo "$BINDIR/NewCandleTime &>/path/to/logfile" | at midnight next sunday
and see if there are any error messages.
 
  


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
nVidia AGP 8x cards...grrr! which one works? Old_Fogie Slackware 25 10-05-2006 08:46 AM

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

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