LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 04-02-2013, 03:02 PM   #1
zimbot
Member
 
Registered: Nov 2005
Location: cincinnati , ohio . USA
Distribution: ubuntu , Opensuse , CentOS
Posts: 122

Rep: Reputation: 17
get a var from a text file and evaluate it against a var


Friends,

I am getting jpgs from a webcam and I wish to know if I Stop getting images
so I get the name of the newest jpg by
img=`exec ls -t | sed -n 2p`
( and that works )
andI wish to store that file name in a test file with
echo $img > /root/00_script/imgNm.txt
( and that seems to work )

but reading the txt file ( imgNm.txt ) back into a var and doing an evluation for are the they same. is NOT working
if [[ $img == $LstImgNm ]];then
echo 'SAME ALERT'
fi
i have do -e & = [[ ]] & [ ]
but i think the problem is getting the 2nd var from the txt file.

and I think that is because I am Not etting the contents of the txt file into the 2nd var $LstImgNm ( last image name )
I have tried a few diffrent ways.


#!/bin/bash
##
## for the mdealer 3.27.2013 js
### attempts at the webpage img
#
#
##############################
####
webD1=/mnt/expan/webcam_ftp
#webD2=/mnt/expan/webcam_img
######### new loc -- may change again for website
webD2=/var/www/html

cd $webD1
### echo pwd
LstImgNm=<$(/root/00_script/imgNm.txt)
#LstImgNm= cat /root/00_script/imgNm.txt
#img=ls -t | sed -n 2p
img=`exec ls -t | sed -n 2p`
## must do the bacTik exec cmd bacTic
echo current is $img
echo previous was $LstImgNm
if [[ $img == $LstImgNm ]];then
echo 'SAME ALERT'
fi
echo current is $img
echo previous was $LstImgNm
## populate the tst file
echo $img > /root/00_script/imgNm.txt
echo stage 2
#cp $webD1/$img $webD2/new.jpg
exit


whe I run it i see
[root@Mixer 00_script]# ./mv_webcam2.sh
/root/00_script/imgNm.txt: line 1: snap_c1_130402_142528.jpg: command not found
/root/00_script/imgNm.txt: line 1: snap_c1_130402_142528.jpg: command not found
./mv_webcam2.sh: line 16: $(/root/00_script/imgNm.txt): ambiguous redirect
current is snap_c1_130402_145529.jpg
previous was
current is snap_c1_130402_145529.jpg
previous was
stage 2

---------------------

and of course I should see
current is snap_c1_130402_145529.jpg
previous was snap_c1_130402_145529.jpg
or at leaste
current is snap_c1_130402_145529.jpg
previous was something.jpg

-------------

thanks
 
Old 04-02-2013, 03:12 PM   #2
zimbot
Member
 
Registered: Nov 2005
Location: cincinnati , ohio . USA
Distribution: ubuntu , Opensuse , CentOS
Posts: 122

Original Poster
Rep: Reputation: 17
also let me say the contents of the txt file is 1 line
snap_c1_130402_152529

and if I change my cde like this

#!/bin/bash
##
## for the mdealer 3.27.2013 js
### attempts at the webpage img
#
#
##############################
####
webD1=/mnt/expan/webcam_ftp
#webD2=/mnt/expan/webcam_img
######### new loc -- may change again for website
webD2=/var/www/html

cd $webD1
### echo pwd
LstImgNm=snap_c1_130402_152529.jpg
#LstImgNm=<$(/root/00_script/imgNm.txt)
#LstImgNm= cat /root/00_script/imgNm.txt
#img=ls -t | sed -n 2p
img=`exec ls -t | sed -n 2p`
## must do the bacTik exe
## must do the bacTik exec cmd bacTic
echo current is $img
echo previous was $LstImgNm
if [[ $img = $LstImgNm ]];then
echo 'SAME ALERT'
fi
echo current is $img
echo previous was $LstImgNm
## populate the tst file
#echo $img > /root/00_script/imgNm.txt
echo stage 2
#cp $webD1/$img $webD2/new.jpg
exit

---------------

then when i run i get

./mv_webcam2.sh
current is snap_c1_130402_152529.jpg
previous was snap_c1_130402_152529.jpg
SAME ALERT
current is snap_c1_130402_152529.jpg
previous was snap_c1_130402_152529.jpg
stage 2

----------------------

so it MUST be the
reading a txt file nto the var.
LstImgNm=<$(/root/00_script/imgNm.txt)

thanks
 
Old 04-02-2013, 10:51 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,225

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
Code:
var=$(cat filename)
& ensure you have no trailing blank lines in the file.

Incidentally, if you add 'set -xv' as the 2nd line, you can see what's happening (what the parser sees and what it does with it)
Code:
#!/bin/bash
set -xv
 
1 members found this post helpful.
Old 04-03-2013, 01:59 AM   #4
kooru
Senior Member
 
Registered: Sep 2012
Location: Italy
Distribution: Slackware, NetBSD
Posts: 1,226
Blog Entries: 4

Rep: Reputation: 250Reputation: 250Reputation: 250
Hi zimbot,

please next time use tag code, so it's easy read your code
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
fsck.ext3 unable to resolve 'label=var' 1.6TB var techux Linux - General 3 03-31-2013 09:02 PM
/var/cache/yum and /var/lib/rpm getting BIG. How to safely pare down? SharpyWarpy Linux - General 3 02-29-2012 01:17 AM
my.cnf on debian squeeze. var names don't match, var values missing. sneakyimp Linux - Server 1 07-03-2011 01:59 AM
file /var/lib/named/var/named/reverse/named.zero failed: file not found Toadman Linux - Software 15 03-18-2009 07:01 PM
pam does not like my owner, group and date for /var/ftp. especially /var manis2008 Linux - Software 1 02-08-2008 07:36 AM


All times are GMT -5. The time now is 12:20 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration