LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 07-13-2008, 03:15 PM   #1
Cheloo
LQ Newbie
 
Registered: Apr 2007
Posts: 10

Rep: Reputation: 0
Unhappy Simple bash script please help!


Hello,

I have the output:

brouter mdstat # md5sum -c /root/mdstat.md5
/proc/mdstat: OK

I would like to have a script that has IF function in it, so every time the output of that md5sum command will have any other output, to echo a message.

I've tried:

Quote:
md5sum /proc/mdstat > /root/mdstat.md5
md5sum -c /root/mdstat.md5 > /root/mdstat.exit

if [ "/root/mdstat.exit" -ne "/proc/mdstat: OK" ]
then
echo "Danger!"
fi
But it gives me errors... what should I do?

Thanks a lot everyone!
 
Old 07-13-2008, 03:35 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
You really could actually tell us what the error is, that's kinda helpful...

I can see that you're using test wrong though, -ne compares two numbers, whereas you are trying to compare to file*NAMES* not the contents of the files or anything past that. you need to use = to compare strings, as the manpage states, but then you've not put much of this in any context so it's hard to work out what you're really doing.

if you want to check a previous md5sum then it's a lot simpler, for example:

md5sum -c /a/b/c.md5 > /dev/null
if [ $? ]
then
... fail ...
else
... pass ...
fi
 
Old 07-13-2008, 03:52 PM   #3
Cheloo
LQ Newbie
 
Registered: Apr 2007
Posts: 10

Original Poster
Rep: Reputation: 0
Tried like this:

Quote:
md5sum /proc/mdstat > /root/mdstat.md5
x=`md5sum -c /root/mdstat.md5`

if [ "$x" -ne "/proc/mdstat: OK" ]
then
echo "Danger!"

fi
but the same error:

[: /proc/mdstat: OK: integer expression expected
 
Old 07-13-2008, 03:54 PM   #4
Cheloo
LQ Newbie
 
Registered: Apr 2007
Posts: 10

Original Poster
Rep: Reputation: 0
stupid me, tried with "!=" and it's working, thanks a lot acid_kewpie!
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Bash Script Filipe Linux - Newbie 2 07-17-2007 09:07 AM
Simple Bash Script sachinh Linux - General 5 05-23-2007 09:54 PM
need help regarding my very simple bash script hottdogg Programming 3 05-02-2007 02:09 AM
Simple Bash Script Help njdownes Programming 2 03-05-2005 07:35 AM
Simple Bash Script dmedici Programming 9 12-31-2004 03:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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