LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-29-2011, 01:42 AM   #1
harinathreddy.c
LQ Newbie
 
Registered: Dec 2010
Posts: 22

Rep: Reputation: 0
validation of tar file


hi folks,

I have to write a script,that should handle below things.

There is already a tgz file comprises of few bin file.

1)i have to calculate the check sum of the file.
2)i have to append that check sum to the same file at end.
3)i have to rename the file.



Req2:

We will download that particular file from website.

Now i have to extract appended check sum and then check sum have to be recalculated.
I have to make sure both check sums are same are not.

If both are same i could make out downloaded tar file hasn't been corrupted.


Kindly plz help me out.
 
Old 08-29-2011, 01:46 AM   #2
nooneknowme
Member
 
Registered: Feb 2008
Location: Bangalore, India
Posts: 69

Rep: Reputation: 5
Hello and Welcome to linuxquestions.org


Regarding the script, can you please let us know where you are facing the problem ? Post the script you have till now so we can help you when you facing the issue.
 
Old 08-29-2011, 04:55 AM   #3
harinathreddy.c
LQ Newbie
 
Registered: Dec 2010
Posts: 22

Original Poster
Rep: Reputation: 0
Hi,

Below is the script.


#!/bin/bash


function execCmd()
{
cmd=$*
$cmd >> $LOG_FILE 2>&1
if [ "$?" != "0" ]
then
add2Log "ERROR : $cmd FAILED in `pwd`"
exit -1
fi
}




function create_usb_upgrade_pkg()
{
export PKG_DIR ="/data/usb/../"
export PKG_NAME ="upgrade_pkg.tgz"
export NEW_PKG = "2.5.4.....firmware"

execCmd md5sum PKG_DIR/PKG_NAME

cat "md5sum string" >> PKG_DIR/PKG_NAME

execCmd mv PKG_DIR/PKG_NAME PKG_DIR/NEW_PKG

}


create_usb_upgrade_pkg


__________________________

My problem is after i calculate i need to append that 32 bit string to the tgz file.After i need to modify the name.
The package with new name will be available in the website.We will download the file.so now i need to write a logic in c to extract that appended string and need to be remove from that file and then have to be calculate md5sum.

Now extracted string and new string should be same.





This is for validation of a file.
Kindly let me know if any fine logic is available to do above thing.



Regards,
Harianth
 
Old 08-29-2011, 05:27 AM   #4
nooneknowme
Member
 
Registered: Feb 2008
Location: Bangalore, India
Posts: 69

Rep: Reputation: 5
As far as i know md5 ... It will change whenever you change anything. when you rename the file, i think the md5 will change..

Why not give the md5 as text as all other software do ?
 
Old 08-29-2011, 06:53 AM   #5
harinathreddy.c
LQ Newbie
 
Registered: Dec 2010
Posts: 22

Original Poster
Rep: Reputation: 0
Hi,

Below is the script.


#!/bin/bash


function execCmd()
{
cmd=$*
$cmd >> $LOG_FILE 2>&1
if [ "$?" != "0" ]
then
add2Log "ERROR : $cmd FAILED in `pwd`"
exit -1
fi
}




function create_usb_upgrade_pkg()
{
export PKG_DIR ="/data/usb/../"
export PKG_NAME ="upgrade_pkg.tgz"
export NEW_PKG = "2.5.4.....firmware"

execCmd md5sum PKG_DIR/PKG_NAME

cat "md5sum string" >> PKG_DIR/PKG_NAME

execCmd mv PKG_DIR/PKG_NAME PKG_DIR/NEW_PKG

}


create_usb_upgrade_pkg


__________________________

My problem is after i calculate i need to append that 32 bit string to the tgz file.After i need to modify the name.
The package with new name will be available in the website.We will download the file.so now i need to write a logic in c to extract that appended string and need to be remove from that file and then have to be calculate md5sum.

Now extracted string and new string should be same.





This is for validation of a file.
Kindly let me know if any fine logic is available to do above thing.



Regards,
Harianth
 
Old 08-29-2011, 08:41 AM   #6
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by nooneknowme View Post
... when you rename the file, i think the md5 will change..
No, a md5sum is calculated over the content.
 
Old 08-29-2011, 09:11 AM   #7
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
Not 100% sure where you see the problem in C.

1)
You can fseek to 32 bytes before the end of the file and find the md5sum that you appended.
2)
You can calculate a new md5sum over the full data except for the last 32 bytes of the file.

Do a search for cryptlib. Quite sure it will contain the md5 algorithm (function) and that way it will prevent you from re-inventing the wheel


PS There is a dedicated programming section here at LQ. Your question might fit better there. If you agree, you can ask a moderator to move the thread by reporting your opening post.

Last edited by Wim Sturkenboom; 08-29-2011 at 09:17 AM.
 
  


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
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 14 10-25-2016 02:48 AM
File system validation ankur0921 Linux - Kernel 0 06-03-2011 03:29 AM
Script to find tar archives, read tar file contents, output content to an index file. bluesword1969 Linux - General 4 02-07-2011 12:15 PM
gave wrong syntax for tar as tar -cvzf file file.tgz how to recover the file gautham Linux - General 4 04-13-2005 03:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:46 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration