Fedora Linux Support Community & Resources Center
  #1  
Old 19th October 2004, 07:46 PM
satimis Offline
Registered User
 
Join Date: Jul 2004
Posts: 1,398
Bash script-confirmation option

Hi folks,

I have following script to create ISO image

#!/bin/bash
Code:
# Set ISO filename...
.....
dir1="/home/satimis/Document/"
dir2="/home/satimis/Photo/"

.....
# Create ISO file...
mkisofs -R -o "$ISO_File" -l -graft-points -hide-rr-moved \
/Document/=$dir1 \
/Photo/=$dir2 \
$list
.....
How to set confirmation on
/Document/=$dir1
/Photo/=$dir2

before the script will continue to proceed,i.e. to have "accept" or "ignore" options on them

Kindly advise. TIA

B.R.
satimis
Reply With Quote
  #2  
Old 21st October 2004, 05:11 PM
pigpen Offline
Registered User
 
Join Date: Nov 2003
Location: Regensburg, Germany
Age: 43
Posts: 447
Sorry, but I don't fully understand your question.
What is it exacty that you want to confirm?
Do you want to confirm if the directories actually exist?
Or do you need some kind of user input in your script?
If your problem has to do with the latter then I'm pretty sure
you will find the answer in the Advanced Bash-Scripting Guide
__________________
/(bb|[^b]{2})/ -- that is the question!

Last edited by pigpen; 21st October 2004 at 05:13 PM.
Reply With Quote
  #3  
Old 22nd October 2004, 03:42 AM
satimis Offline
Registered User
 
Join Date: Jul 2004
Posts: 1,398
Hi pigpen,

Tks for your response and URL

I re-organize my question as follows in anticipation to make it clearer;

I have following command line embedded on a desktop icon and a script. They work for me.

Command line

Code:
xterm -hold -T "CDMaker by satimis" -e "su -c /path/to/cdmake"
Script
Code:
#!/bin/bash
# Set ISO filename...
user=$(whoami)
now=$(date +%Y.%m.%d.%R)
ISO_File="/home/satimis/To_burn/image_${user}_${now}.iso"
dir1="/home/satimis/Document/"
dir2="/home/satimis/Photo/"

# Loop to get directories...
echo "Enter directories to burn.  Leave blank to end list"
entry="empty"
list=""
count=0
until [ -z $entry ]; do
  echo -n "Enter a directory: "
  read entry
  if [ $entry != "" ]; then
    list="$list $1$entry"
  fi
done

# Create ISO file...
mkisofs -R -o "$ISO_File" -l -graft-points -hide-rr-moved \
/Document/=$dir1 \
/Photo/=$dir2 \
$list

# Burn ISO file to disc
cdrecord dev=ATA:0,0,0 -v -eject “$ISO_File”

# Remove ISO file
rm “$ISO_File”
Steps taken as follow;
1)Clicking the icon starting xterm
2)Enter password to login as root
3)Enter further directories, if any, with corresponding path in the form of “/Dir_AAA/=/path/to/Dir_AAA, etc. (cdrecord format). (If no further entry just hit <Enter> to continue)

Remark:
dir1="/home/satimis/Document/"
dir2="/home/satimis/Photo/"
are permanently added.

Then the script will take care of the rest and a CD is burnt finally.

Now I need to re-edit;
1)The command line as

Code:
xterm -hold -T "CDMaker by satimis" -e /path/to/cdmake"
Let the script to handle login as root to execute commands on background.

2)Re-edit the script to perform

a)
Login as root after ISO_File created because USER is not allowed to burn CD.
(I don't want to add USER to the wheel using this route. Hoping to learn more on script)

b)
Re-edit the script to perform following steps.

b-1)
The script is evoked by the revised command line

b-2)
Before
dir1="/home/satimis/Document/"
dir2="/home/satimis/Photo/"

are added, confirmation is now required. It will pop up for entry of “yes” or “no”. If “yes” they will be added. If “no” they will not be added. The script will continue to next command asking for adding of further directory/directories with corresponding path.

Remark:
dir1="/home/satimis/Document/"
dir2="/home/satimis/Photo/"
are still added on the script

b-3)
After an ISO_file created, it will continue to login as root asking for input of root password.

b-4)
After a CD burnt, xterm will close. I'll remove the option “-hold” later to get it done.

Please advise. I'm now getting into some confusing.

TIA

B.R.
Satimis
Reply With Quote
  #4  
Old 23rd October 2004, 12:17 PM
pigpen Offline
Registered User
 
Join Date: Nov 2003
Location: Regensburg, Germany
Age: 43
Posts: 447
Here's what you might need:
Code:
[pigpen@mybox pigpen]$ cat dialog.sh
#!/bin/bash
dialog --inputbox "Shall we do it or not?" 10 60
if [ $? != 0 ] ; then
        echo "Coward ;-)"
        exit
else
        echo "OK! Here we go..."
fi
Pops up a dialog box. The script exits if you hit "Cancel".
__________________
/(bb|[^b]{2})/ -- that is the question!
Reply With Quote
  #5  
Old 23rd October 2004, 05:07 PM
satimis Offline
Registered User
 
Join Date: Jul 2004
Posts: 1,398
Hi pigpen,

Tks for your advice.

I have no idea where shall I put following 2 lines
/Document/=$dir1 \
/Photo/=$dir2

I tried several positions;
Code:
......
# Create ISO file...
mkisofs -R -o "$ISO_File" -l -graft-points -hide-rr-moved \
$list \

dialog --inputbox "Shall we do it or not?" 10 60
/Document/=$dir1 \
/Photo/=$dir2
if [ $? != 0 ]" ; then
        echo "Coward ;-)"
        exit
else
        echo "OK! Here we go..."
fi
......
so that they will appear inside the box one after another
(i.e.
/Document/=/home/satimis/Document/
hit <OK>
/Photo/=/home/satimis/Photo/
hit <OK>)

Then the script will continue to create ISO File
(Remark: I re-positioned the line "$list \")

Please advise. TIA

B.R.
satimis
Reply With Quote
  #6  
Old 23rd October 2004, 10:06 PM
pigpen Offline
Registered User
 
Join Date: Nov 2003
Location: Regensburg, Germany
Age: 43
Posts: 447
How about saving the exit codes of the 'dialog' program in two variables and evaluate them later?
I haven't tried, but
Code:
dialog --inputbox $dir1 10 60
should work, too.
BTW: I still think, that http://www.tldp.org/LDP/abs/html/ would be a valuable resource for you.
__________________
/(bb|[^b]{2})/ -- that is the question!
Reply With Quote
  #7  
Old 24th October 2004, 02:20 AM
satimis Offline
Registered User
 
Join Date: Jul 2004
Posts: 1,398
Hi pigpen,

Tks for your advice and URL. I tried but unfortunately it did not work.

"$dir" became the name of the box.

Following works to put "/Document/=/home/satimis/Document" inside the box

Code:
# Create ISO file...
mkisofs -R -o "$ISO_File" -l -graft-points -hide-rr-moved \
$list \

dialog --inputbox  "Shall we do it or not?" 10 60
/Document/=$dir \
if [ $? != 0 ] ; then
        echo "Coward ;-)"
        exit
else
        echo "OK! Here we go..."
fi
ISO File created finally but excluding the directory "/Document/=/home/satimis/Document"

I still can't find a solution.

B.R.
satimis
Reply With Quote
  #8  
Old 24th October 2004, 04:57 PM
pigpen Offline
Registered User
 
Join Date: Nov 2003
Location: Regensburg, Germany
Age: 43
Posts: 447
I don't want to take the fun out of your programming experience by writing the script for you.
Therefore I give you this link: http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
The only way to become a programmer is through experience. And it's fun, too, I promise
__________________
/(bb|[^b]{2})/ -- that is the question!
Reply With Quote
  #9  
Old 24th October 2004, 05:03 PM
satimis Offline
Registered User
 
Join Date: Jul 2004
Posts: 1,398
Hi pigpen,

Tks for your URL.

I tried several hours discovering follows finally;

1)
Code:
....
# Create ISO file...
mkisofs -R -o "$ISO_File" -l -graft-points -hide-rr-moved \
/Document/=$dir1 \
/Photo/=$dir2 \
$list
....
The above lines can't be separated otherwise "mkisofs" won't work.

2)
The possible solution is creating new directories "/home/satimis/Temp/dir1", "/home/satimis/Temp/dir2" and do the trick on the beginning of the script;


I made following test;

3A)
$ mkdir /home/satimis/Temp/dir1
$ mkdir /home/satimis/Temp/dir2

3B)
Edited the script as follow;
Code:
#!/bin/bash

# Set ISO filename...
user=$(whoami)

now=$(date +%Y.%m.%d.%R)
ISO_File="/home/satimis/To_burn/image_${user}_${now}.iso"
dir1=/home/satimis/Temp/dir1/
dir2=/home/satimis/Temp/dir2/

read -p "Add Document directory?"
if [ "$REPLY" = "yes" ]; then
  cp -r /home/satimis/Document/* /home/satimis/Temp/dir1/
else
   cancel
fi

read -p "Add Photo directory?"
if [ "$REPLY" = "yes" ]; then
  cp -r /home/satimis/Photo/* /home/satimis/Temp/dir2/
else
   cancel
fi

# Loop to get directories...
echo "Enter directories to burn.  Leave blank to end list"
entry="empty"
list=""
until [ -z $entry ]; do
  echo -n "Enter a directory: "
  read entry
  if [ $entry != "" ]; then
    list="$list $1$entry"
  fi
done

# Create ISO file...
mkisofs -R -o "$ISO_File" -l -graft-points -hide-rr-moved \
/Document/=$dir1 \
/Photo/=$dir2 \
$list

# Burn ISO file...
cdrecord dev=ATA:1,0,0 -v -eject "$ISO_File"

# Delete diretories and files...
rm -r /home/satimis/Temp/dir1/* /home/satimis/Temp/dir2/*

# Delete ISO file...
rm "$ISO_File"
Although I solve the probem now. But this is a stupid way which takes longer time to complete because of copying directories and files to "Temp directories" and deleting them thereafter.

Have you had any suggestion.

TIA

B.R.
satimis
Reply With Quote
Reply

Tags
bash, option, scriptconfirmation

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Script Help Jamwa Using Fedora 5 17th June 2008 05:26 PM
Convert bash script to perl script homey Programming & Packaging 1 2nd September 2006 04:24 AM
Bash Script svenkatesan Using Fedora 0 3rd May 2006 04:49 AM
cgi bash script paul_mat Using Fedora 1 18th April 2006 04:17 PM
BASH script help ryan.overton Using Fedora 3 1st March 2006 01:52 PM


Current GMT-time: 13:43 (Thursday, 30-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Cileungsir Instagram Photos - Kundian - Avocado Heights