LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 09-09-2008, 07:21 AM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 30
script error


I have below script

chka =$( cksum /tmp/file1 )
chkb =$( cksum /tmp/file2 )
echo $chka
echo $chkb


I would like to echo the cksum , but after run it , it pop the below message , can advise what is wrong ( if run it on shell , it is OK ) ? thx


cksum: /tmp/: Is a directory
 
Old 09-09-2008, 07:59 AM   #2
antegallya
Member
 
Registered: Jun 2008
Location: Belgium
Distribution: Debian
Posts: 109

Rep: Reputation: 42
Hi,

Is that exactly your script ?
And if you add the line
Code:
if [ -f /tmp/file1 ]; then echo "OK"; else echo "KO"; fi
does the file is accessible within the script ?
 
Old 09-09-2008, 08:04 AM   #3
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Lose the space before the "="
 
Old 09-09-2008, 09:24 AM   #4
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by billymayday View Post
Lose the space before the "="
thx ,

you are right,

I have one more question , I use the cksum to check the file as below script


chka =$( cksum /tmp/file1 )
chkb =$( cksum /tmp/file2 )
echo $chka
echo $chkb

if [[ $chka != $chkb ]]
then
echo "error"
done
eles
do ...
done
fi


but I found that it must have error because when use cksum /tmp/file1 , the output is "12151458452 76276 /tmp/file1" and cksum /tmp/file2 , the output is "12151458452 76276 /tmp/file2" , the file name is different , so they must different and echo "error" , can advise how to only use cksum to show the byte of file so that I can only compare the size ? thx
 
Old 09-09-2008, 09:34 AM   #5
antegallya
Member
 
Registered: Jun 2008
Location: Belgium
Distribution: Debian
Posts: 109

Rep: Reputation: 42
If you just want the file size, you can use
wc -c /tmp/file1
but I think you want to compare the checksum plus the size so just do a
cksum /tmp/file | grep -o "^[0-9]* [0-9]*"
 
Old 09-09-2008, 09:45 AM   #6
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by antegallya View Post
If you just want the file size, you can use
wc -c /tmp/file1
but I think you want to compare the checksum plus the size so just do a
cksum /tmp/file | grep -o "^[0-9]* [0-9]*"

thx,

it is good , but if the some file name begins numeric , what can i do ? thx
 
Old 09-09-2008, 04:31 PM   #7
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Code:
cksum /tmp/file1 | cut -d ' ' -f1,2
 
  


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
why am getting error ksh: syntax error: `fi' unexpected while running script deb4you Linux - Newbie 4 09-06-2008 09:37 AM
bash script read error and awk ouptut error whited Programming 4 10-16-2007 08:05 PM
i get an error message running php script inside a cgi script. repolona Linux - Software 0 02-22-2007 10:10 PM
error when tying to run python script(bash error?) shanenin Programming 5 01-10-2006 11:01 AM
linux 9 and java script error - premature end of script header sibil Linux - Newbie 0 01-06-2004 05:21 PM


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