Register
It is currently Thu Jul 24, 2014 3:39 pm

How to put this in a script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Sat Aug 21, 2010 4:06 am   

Joined: Sat Aug 21, 2010 3:36 am
Posts: 14
I have ISO files on a directory say for example:

/home/username/

I want to rar each file with specifically the command below:

rar a -k -m5 -ppassword '[ubuntu] - 0001.rar' '0001 - Ubuntu[Warty Warthog].iso'

Note: all files have spaces and some special characters on them.

Question:
How can I put this on script so I do not have to do it one by one?
I am assuming use a loop such as do or for loop?


Top
 Profile  
 PostPosted: Sat Aug 21, 2010 8:23 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
Yo,

I'm not familiar with rar and it's not clear how you intend to use the filename. It kinda looks like you need some filename info for the passwd switch.
Let's start with this, you may be able to adjust it suitably;

Code:
#!/bin/bash

cd /home/username/
ls *.iso | while read ifile
do
  rar a -k -m5 -ppassword '[ubuntu] - 0001.rar' "$ifile"
done


This may include the useless use of 'ls'...

DW


Top
 Profile  
 PostPosted: Sat Aug 21, 2010 12:23 pm   

Joined: Sat Aug 21, 2010 3:36 am
Posts: 14
Thanks
DarthWavy wrote:
Yo,

I'm not familiar with rar and it's not clear how you intend to use the filename. It kinda looks like you need some filename info for the passwd switch.
Let's start with this, you may be able to adjust it suitably;

Code:
#!/bin/bash

cd /home/username/
ls *.iso | while read ifile
do
  rar a -k -m5 -ppassword '[ubuntu] - 0001.rar' "$ifile"
done


This may include the useless use of 'ls'...

DW


hi Darth Wavy thanks for the reply is it okay if I ask what the below line of code does?

Code:
ls *.iso | while read ifile


I think there will be some issue as all archived file will have this name "[ubuntu] - 0001.rar" correct? wherein every loop it will be overwritten
Can you shed some light how to rar the files and name them based on their original name?


Top
 Profile  
 PostPosted: Sun Aug 22, 2010 12:53 am   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
This should create output files based on the inputfile with .iso replaced with .rar

Code:
#!/bin/bash

cd /home/username/
for ifile in *.iso
do
  ofile=${ifile%.iso}.rar
  rar a -k -m5 -ppassword "$ofile" "$ifile"
done


Top
 Profile  
 PostPosted: Sun Aug 22, 2010 5:39 am   

Joined: Sat Aug 21, 2010 3:36 am
Posts: 14
Patsie wrote:
This should create output files based on the inputfile with .iso replaced with .rar

Code:
#!/bin/bash

cd /home/username/
for ifile in *.iso
do
  ofile=${ifile%.iso}.rar
  rar a -k -m5 -ppassword "$ofile" "$ifile"
done


Holy moly it worked like a charm a billion thanks Patsie =))


Top
 Profile  
 PostPosted: Sun Aug 22, 2010 8:17 am   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
You're welcome.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP