ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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)
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.
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
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.