LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Simple bash script please help! (https://www.linuxquestions.org/questions/linux-general-1/simple-bash-script-please-help-655509/)

Cheloo 07-13-2008 03:15 PM

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!

acid_kewpie 07-13-2008 03:35 PM

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

Cheloo 07-13-2008 03:52 PM

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

Cheloo 07-13-2008 03:54 PM

stupid me, tried with "!=" and it's working, thanks a lot acid_kewpie!


All times are GMT -5. The time now is 02:23 AM.