LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 10-16-2004, 03:49 AM   #1
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,006

Rep: Reputation: 48
Question on creating icon to execute commands


Hi folks,

I have prepared following script to create ISO image and burn the same on CD afterwards;

Code:
#!/bin/bash
if [ -z "${1:-}" ]; then
   ( echo "Usage: $0 imagepostfix [pathspec...]" ; echo ) >&2
   exit 2;
fi

ISO_File="/path/to/To_burn/Image_${1}.iso"

shift
mkisofs -R -o "$ISO_File" -l -graft-point -hide-rr-moved \
/dir-1/=/path/to/dir-1/ \
/dir-2/=/path/to/dir-2/ \
/dir-3/=/path/to/dir-3/ \
/dir-4/=/path/to/dir-4/ "$@"

shift
cdrecord dev=ATA:1,0,0 -v -eject "$ISO_File"
# ./cdmaker xyz /dir-5/=/path/to/dir-5/ /dir-6/=/path/to/dir-6/ etc.

It works for me seamlessly.

I can create an icon executing the command "./cdmaker ABC" to create ISO image and burn the same on CD, if the name of ISO image fixed and no addition of further directory/directories. But if they are necessary then how to re-editing the script so that mini-windows will be popup for entering "name of ISO image" and "directories including their paths"

Please advise. TIA

B.R.
satimis

Last edited by satimis; 10-16-2004 at 03:50 AM.
 
Old 10-16-2004, 08:07 AM   #2
ranger_nemo
Senior Member
 
Registered: Feb 2003
Location: N'rn WI -- USA
Distribution: Kubuntu 8.04, ClarkConnect 4
Posts: 1,142

Rep: Reputation: 46
Your first conditional checks that there are command-line arguments. If it finds them, the script continues normally. If it doesn't find them, you can use a read command to have the user input what is needed...
Code:
echo -n "What is your name? "
read name
echo -n "What is your quest ? "
read quest
echo -n "What is your favorite color? "
read color
echo $name $quest $color
Then, you could use xterm to launch your script. The command for the icon would be something like...

xterm -hold -T "cdmaker by satimis" -e /path/to/cdmaker

The "-hold" keeps the new xterm window open after the script is done. The "-T" changes the title of the new window. And the "-e" executes the command in the new window.

## EDIT ##

If you are looking to make GUI input windows, you'll need something other than bash.

Last edited by ranger_nemo; 10-16-2004 at 08:10 AM.
 
Old 10-16-2004, 11:22 AM   #3
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,006

Original Poster
Rep: Reputation: 48
Hi ranger_nemo,

Tks for your advice which is quite interesting. GUI input window is another approach not in this posting.

The command line used by me "to create ISO Image and to burn it on CD" is;

# ./cdmaker xyz /dir-1/=/path/to/dir-1/ /dir-2/=/path/to/dir-2/ etc.

What I need is a bash script which will ask questions on an xterm window. The latter is evoked with an icon;

Steps
1) Asking for input of Image number
xyz
2) Asking for 1st directory input
/dir-1/=/path/to/dir-1/
3) Asking for 2nd directory input
/dir-2/=/path/to/dir-2/
etc.
4) Input last directory plus a code to stop further question
5) Continue to proceed creating Image and then burning CD

Kindly advise how to edit the script to perform above steps based on your suggestion.

TIA

B.R.
satimis
 
Old 10-16-2004, 09:54 PM   #4
ranger_nemo
Senior Member
 
Registered: Feb 2003
Location: N'rn WI -- USA
Distribution: Kubuntu 8.04, ClarkConnect 4
Posts: 1,142

Rep: Reputation: 46
Code:
#!/bin/bash

# Set ISO filename...
user=$(whoami)
now=$(date +%Y.%m.%d.%R)
ISO_File="/tmp/image_${user}_${now}.iso"

# 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
    count=$(($count+1))
    list="$list dir$count=$entry"
  fi
done

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

# Burn ISO file to disc...
cdrecord dev=ATA:1,0,0 -v -eject "$ISO_File"
This is prob'ly pretty rough... I haven't done much bash scripting lately. I had it create a filename for the ISO rather than ask for one. You can change that if you want.
 
Old 10-17-2004, 06:50 AM   #5
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,006

Original Poster
Rep: Reputation: 48
Hi ranger_nemo,

Lot of tks for your advice and script which works for me seamlessly.

I only made following minor alternations.

1A)
ISO_File="/home/satimis/To_burn/image_${user}_${now}.iso"
(to save ISO image on /home/satimis/To_burn/

1B)
list="$list $entry"
(allow the entry of directory in the form of "/Photo/=/home/satimis/Photo/"
"/cups/=/home/satimis/cups/"
etc.
corresponding to "cdrecord" syntax and to input "directory name" directly)

1C)
mkisofs -R -o "$ISO_File" -l -graft-points -hide-rr-moved \
/Document/=/home/satimis/Document/ \
/Photo/=/home/satimis/Photo/ \
$list

(These 2 directories are added permanently)


On cearting ISO image following warning appeared;
Code:
.......
./burncd_01: line 16: [: !=: unary operator expected
INFO:   UTF-8 character encoding detected by locale settings.
        Assuming UTF-8 encoded filenames on source filesystem,
        use -input-charset to override.
Using BAD_RAGAZ16653345ILUDYKV000.JPG;1 for  /home/satimis/Photo/Chur-Swiss/Bad_Ragaz16653345IlUDykVODb_ph.jpg (Bad Ragaz16653345IlUDykVODb_ph.jpg)
....
I don't understand what it is. However ISO image was created disregarding this warning.

Following command
xterm -hold -T "cdmaker by satimis" -e /path/to/cdmake
(also worked. An executable ICON has been created working without problem)


The remaining problems are;

2A)
"cdrecord" only works as "root" I have to login as "root" to execute the ICON

Would it be possible to adjust the "script" to popup "requesting root password" to proceed while working as USER


2B)
Is it possible to delete the ISO image automatically after burning completed. If possible kindly advise how to adjust the script

TIA

B.R.
satimis
 
Old 10-18-2004, 06:21 AM   #6
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,006

Original Poster
Rep: Reputation: 48
Hi ranger_nemo,

Further to my last posting.

Problem solved with following command line;

xterm -hold -T "CDMaker by satimis" -e "su -c /path/to/cdmake"

Now with a click on a desktop icon I can burn a CD including all pre-selected directories plus directories input later.

The remaining job is how to automatically delete the ISO image thus created and to close the xterm window after all steps completed.

Could you please help me to understand follows;
Quote:
entry="empty"
list=""
count=0
until [ -z $entry ]; do
echo -n "Enter a directory: "
read entry
if [ $entry != "" ]; then
count=$(($count+1))
list="$list dir$count=$entry"
TIA

B.R.
satimis
 
Old 10-18-2004, 06:54 AM   #7
ranger_nemo
Senior Member
 
Registered: Feb 2003
Location: N'rn WI -- USA
Distribution: Kubuntu 8.04, ClarkConnect 4
Posts: 1,142

Rep: Reputation: 46
To delete the ISO file, you just need to add an "rm -f ISO_filename" line to the end of the script.

To close the xterm window after the script completes, just remove the "-hold" option out of the command that starts the script.

The section just loops and asks for the directories to add. I changed it a bit here...
Code:
# Loop to get directories...
echo "Enter directories to burn.  Enter 'done' to end list"
entry="empty"
list=""
count=0
until [ $entry = "done" ]; do
  echo -n "Enter a directory: "
  read entry
  if [ $entry != "done" ]; then
    count=$(($count+1))
    list="$list dir$count=$entry"
  fi
done
Until you enter done, it keeps asking for a dir. It has a counter that it adds one to each time a dir is entered. It uses this counter to make the dir#=/entered/dir , and appends it to the current list of dirs.

I don't think I would run the script as root "su -c"... If somebody editted it, it could do anything as root. I'm off to work, so I don't have time to look into permissions, but if worst came to worst and cdrecord MUST be run as root, I would put the "su -c" into the script and have it just do the cdrecord line. Not a whole lot better, really, somebody could still maliciouly edit the script.
 
Old 10-19-2004, 11:55 AM   #8
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,006

Original Poster
Rep: Reputation: 48
Hi ranger_nemo,

Tks for your revised script.

Test performed as follow but can't burn CD

Embedded command on ICON
xterm -hold -T "cdmaker by satimis" -e /home/satimis/cdmaker

cat /home/satimis/cdmaker
Code:
#!/bin/bash

# Login as root
su -c "-e /home/satimis/cdmaker"

# Set ISO filename...
user=$(whoami)
now=$(date +%Y.%m.%d.%R)
ISO_File="/home/satimis/To_burn/image_${user}_${now}.iso"

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

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

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

# Remove ISO file
#rm "$ISO_File
“-e /home/satimis/cdmaker”
must be entered twice, embedded on ICON as well as on “cdmaker”. Otherwise xterm window started but after entering password no further entry was allowed

Clicked ICON to start xterm windown
Code:
Password
bash: - : invalid option
Enter directories to burn.  Enter 'done' to end list
Enter a directory: /Cups/=/var/log/cups
Enter a directory: done

...........

cdrecord: Drive does not support TAO recording
cdrecord: Illegal write mode for this drive
Burning CD failed but Image created on /home/satimis/To_burn/

Image can be burned manually with following command;
# cdrecord dev=ATA:0,0,0 -v -eject /home/satimis/To_burn/image_satimis_2004.10.19.20\:32.iso

Kindly advise how to fix the problem. TIA

B.R.
satimis
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can I execute two commands on exec of a find? eantoranz Programming 3 08-03-2010 04:51 PM
cannot execute some commands as an plain user! minike Slackware 5 09-03-2004 06:34 PM
how can execute some commands when a user logs out rddreamz Programming 2 05-25-2004 03:00 PM
C -how do i execute linux commands? ocularbob Programming 7 02-29-2004 01:51 PM
how to execute commands on login k4zau Linux - Software 3 10-12-2003 01:52 PM


All times are GMT -5. The time now is 02:59 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration