LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-26-2012, 12:42 AM   #1
gajananh999
Member
 
Registered: Aug 2012
Posts: 94

Rep: Reputation: Disabled
Catch result of extract file of 7z


Dear All,

I have written a batch file which do the extract .7z files from specific folder so i want to check weather file is successfully extracted or no

Here is my code
Code:
#!/bin/bash
FILES=/logs/isac/collation/data/server1/*.7z
for f in $FILES
do
  echo "Processing $f file..."
  # take action on each file. $f store current file name
   res=7za u -o/logs/isac/collation/data/logs2/ "$f"
   echo $res

done
Its giving error saying

./isacExtractor: line 7: u: command not found

Last edited by gajananh999; 10-26-2012 at 12:52 AM.
 
Old 10-26-2012, 01:03 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
This generates the error:
Code:
res=7za u -o/logs/isac/collation/data/logs2/ "$f"
If you want to store the output of a command in a variable you need to do this:
Code:
var="$(command)"
So the line in question should look like this:
Code:
res="$(7za u -o/logs/isac/collation/data/logs2/ "$f")"
 
Old 10-26-2012, 01:20 AM   #3
gajananh999
Member
 
Registered: Aug 2012
Posts: 94

Original Poster
Rep: Reputation: Disabled
Dear druuna,

It worked but its not returning any value when i m doing echo $var it printing nothing.
 
Old 10-26-2012, 01:25 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by gajananh999 View Post
Dear druuna,

It worked but its not returning any value when i m doing echo $var it printing nothing.
Shouldn't that be echo $res
Code:
#!/bin/bash
FILES=/logs/isac/collation/data/server1/*.7z
for f in $FILES
do
  echo "Processing $f file..."
  # take action on each file. $f store current file name
   res="$(7za u -o/logs/isac/collation/data/logs2/ "$f")"
   echo $res

done
 
Old 10-26-2012, 01:49 AM   #5
gajananh999
Member
 
Registered: Aug 2012
Posts: 94

Original Poster
Rep: Reputation: Disabled
Dear druuna,

But $res is not printing anything
 
Old 10-26-2012, 02:22 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by gajananh999 View Post
But $res is not printing anything
What is happening when you run the script? Do you get an error message, does it run without any message to screen, do you get the prompt back?

Also: Are you sure you want to use the u switch (which is for updating) and not the e switch (which is for extracting)?
 
Old 10-26-2012, 02:22 AM   #7
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Just do this:

Code:
if ! 7za u -o/logs/isac/collation/data/logs2/ "$f"
then
    echo "Extracting $f failed"
fi
 
Old 10-26-2012, 02:29 AM   #8
gajananh999
Member
 
Registered: Aug 2012
Posts: 94

Original Poster
Rep: Reputation: Disabled
Dear druuna,

I wont get any error massage but i get back to prompt

and u is use for extract and put the file in specified directory if already present also

and e is use to extract the files.

---------- Post added 10-26-12 at 02:30 AM ----------

Dear H_TeXMeX_H,

Its giving error

$ ./isacExtractor
./isacExtractor: line 7: syntax error near unexpected token `then'
./isacExtractor: line 7: `then'
 
Old 10-26-2012, 02:34 AM   #9
gajananh999
Member
 
Registered: Aug 2012
Posts: 94

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by H_TeXMeX_H View Post
Just do this:

Code:
if ! 7za u -o/logs/isac/collation/data/logs2/ "$f"
then
    echo "Extracting $f failed"
fi
this worked fine but how to get else condition on this....?
 
Old 10-26-2012, 02:38 AM   #10
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Quote:
Originally Posted by gajananh999 View Post
this worked fine but how to get else condition on this....?
You can also make it more straightforward:

Code:
if 7za u -o/logs/isac/collation/data/logs2/ "$f"
then
    echo "Extracting $f successful"
else
    echo "Extracting $f failed"
fi
 
1 members found this post helpful.
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to do search & replace on a text file--need to extract URLs from a sitemap file Mountain Linux - General 4 08-07-2015 10:52 AM
Prompt the user for a file to open, extract the XML and write to another text file. richiep Linux - Newbie 7 10-22-2010 03:34 PM
how to catch the return value of dialog without temp file ? doublehp Linux - Software 1 05-20-2005 10:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:35 AM.

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