LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 05-17-2010, 12:13 PM   #1
smoooth103
Member
 
Registered: Aug 2009
Location: NC, USA
Distribution: Slackware (64 bit)
Posts: 237

Rep: Reputation: 58
Bash Script Question / Slackpkg


I want my system to email me when there is an update available via slackpkg. I decided to try a bash script to do the notification. So I started down this route:

VAR = $(slackpkg check-updates)
VAR1 = "No news is good news "
if [ "$VAR" = "$VAR1" ] then; . . .

I keep getting an error on the string comparison. I am guessing the variable types are different but I can't figure out how to fix it. Does anyone know how I can fix this script or accomplish the task at hand.
 
Old 05-17-2010, 12:21 PM   #2
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
Make sure you have the syntax correct. The ';' goes before the then, and the variables don't get a space before or after the equal sign in their assignment. A space does go between the variables and the equal sign in the [ command.

Code:
#!/bin/sh
VAR="No news is good news "
VAR1="No news is good news "
if [ "$VAR" = "$VAR1" ] ; then
    echo asdf
fi
Wasn't sure if your code has the typos or your post does.

HTH

Forrest
 
Old 05-17-2010, 12:30 PM   #3
smoooth103
Member
 
Registered: Aug 2009
Location: NC, USA
Distribution: Slackware (64 bit)
Posts: 237

Original Poster
Rep: Reputation: 58
I'm pretty sure the syntax I used was correct but I just typed carelessly in the message above. It looked like a "data type" error because I outputted the VAR and VAR1 and they looked to both be exactly the same. I check for '/n' and other escape characters and there weren't any. When I ran it there was an error and it also returned "false" when it should have been "true."

When I call the VAR=$(slackpkg check-updates) that should return a standard string right?
 
Old 05-17-2010, 12:38 PM   #4
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
Well, I don't use Slack, so I don't have slackpkg. However, there also won't be a space at the end of the output, so that will also cause it to not match.

HTH

Forrest
 
Old 05-17-2010, 12:46 PM   #5
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 547

Rep: Reputation: 115Reputation: 115
I use this in crontab.daily:

Code:
updates=`slackpkg check-updates`
num_updates=`echo $updates | grep -v "No news" | grep -v "^$" | wc -l`

if [ $num_updates -gt 0 ]
then
        echo -e $updates "\n\nRun 'updatesystem' as root to install." | mail -r "Root" -s "Slackware Package Updates Available" myusername
fi
I preferred it that way to checking against a string variable.
 
1 members found this post helpful.
Old 05-17-2010, 12:55 PM   #6
smoooth103
Member
 
Registered: Aug 2009
Location: NC, USA
Distribution: Slackware (64 bit)
Posts: 237

Original Poster
Rep: Reputation: 58
Thanks, I will try your method posted above.
 
  


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
Bash script CD question olan Linux - Newbie 6 11-06-2009 02:57 AM
bash script question soybean pete Linux - General 5 05-23-2007 11:33 AM
Bash script question deiussum Programming 6 08-14-2004 11:43 AM
bash script question xscousr Programming 5 07-03-2003 05:04 PM
Bash script question J_Szucs Linux - General 4 05-29-2003 08:48 AM


All times are GMT -5. The time now is 01:54 AM.

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