Results 1 to 5 of 5
First off, I am pretty new to bash/shell scripting so sorry if this is "elementary" to some of you.
I am currently proactively replacing several server drives for my company. ...
- 05-26-2010 #1Just Joined!
- Join Date
- Nov 2009
- Posts
- 5
Compare Output of 2 Files and Determin Whether or Not to Continue
First off, I am pretty new to bash/shell scripting so sorry if this is "elementary" to some of you.
I am currently proactively replacing several server drives for my company. The company has its own Linux Dist and we have several versions of software in the field. While replacing the server I have to confirm the that new Server Drive is running an equal or newer version of software.
I have written a script that will restore all the data but I am stumped with this area.
I want the script to check the version of hda (filename1) and check the version of hdb (filename2). If the software on hda is older I would like the script to prompt me to upgrade the new drive to a newer version before proceeding. If hdb is equal that is fine but it cannot be a newer version or it will corrupt the SQL tables.
Thank You for any advice on this topic.
- 05-26-2010 #2Just Joined!
- Join Date
- May 2010
- Posts
- 7
What's the format of the version #s?
- 05-26-2010 #3Just Joined!
- Join Date
- Nov 2009
- Posts
- 5
For hda, I cat the file ie cat /etc/version
Output ex is "v2.55 (10-10-2009)"
For hdb, I mount the old drive to /tmp/second_drive
cat /tmp/second_drive/etc/version
Output ex is "v2.51 (3-15-2009)"
Hopefully I answered the question acuratly. Please let me know if there is anything else you would like me to add.
Thanks
- 05-26-2010 #4Just Joined!
- Join Date
- Nov 2009
- Posts
- 5
I just thought if you meant what format of scripting it is
#!/bin/sh
- 05-26-2010 #5Just Joined!
- Join Date
- May 2010
- Posts
- 7
Can you use perl for something like:
I haven't full tested the above code, but I think it's correct. Should be close enough to get you started. Let me know if perl is not an option.Code:VA=`cat /etc/version | perl -ne 'if (/v(\d+\.\d+) \s+\(\d+-\d+-\d+\)/) { print $1 }'` VB=`cat /tmp/seconddrive/etc/version | perl -ne 'if (/v(\d+\.\d+) \s+\(\d+-\d+-\d+\)/) { print $1 }'` # bash numerical comparisons are integer based, so back to perl for if [ 1 == x`perl -e "if ($VA < $VB) { print 1; }"`


Reply With Quote