Author Topic: [SOLVED] Code Problem?  (Read 984 times)

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6849
  • MLU
[SOLVED] Code Problem?
« on: October 02, 2010, 01:33:48 PM »
I have quoted an excerpt of the code in question below. I have arranged it so that it runs as a script.
I have added the display of the "found" device for completeness to the end of it.

This is from the LiveUSB script.

There have been two reports of a problem .....  seemingly not always present .....  of a problem when running the script.

The section in question detects what drives are attached to the PC, then asks the user to insert a USB drive, click on the button, and the drives are detected again.
After a comparison between the two lists of drives the new one is known.

The problem appears to be that on attempted detection of the drives  the command is not found!
(edited by johnboy)
The command is "sfdisk".

The error is

Code: [Select]
/usr/bin/lusbc.sh: line 139: sfdisk: command not found
The line number of course is different in the segment quoted below.
The line that errors is
Code: [Select]
DRIVES2=$(sfdisk -s | grep -e /dev/ | cut -d: -f1)
Also the first time it is called has been known to fail
Code: [Select]
/usr/bin/lusbc.sh: line 111: sfdisk: command not found
So the question is ........  is there something wrong with the script that could be causing this?
Is there maybe something not well known that might cause it?

It has happened for two users that I know of .......  Neal and scoundrel
So the hardware is different.

I believe that both were running LXDE ......  but how would thay make any difference?

I am at a loss, but would like to try to get to the bottom of this as soon as possible.
The script is about to be updated abd it would be preferable if this problem was not hanging over it ........

All suggestions welcome ...........

Code: [Select]
#!/bin/bash
set -x

zenity --question --width=650 --no-wrap  --title="        Deciding on the Install Device        " --text="

                 Please ensure that the device you intend to use    

                               is    <span color='"'red'"'><b>NOT</b></span>   plugged in, else

withdraw it now and wait a few seconds before selecting    <span color='"'blue'"'><b>Yes</b></span>    below.

You must ensure you do not plug in or withdraw any device other than the

            one intended for the OS, while this application is running.

                Are you ready to proceed with the LiveUSB install?

                     Selecting      <span color='"'red'"'><b>No</b></span>     will exit the application.
" $?
if [ $? != 0 ] ; then kill $mypid ; exit
fi
DRIVES1=$(sfdisk -s | grep -e /dev/ | cut -d: -f1)
zenity --question --width=550  --title="Plugging in your USB Device" --text="


           <b> Please plug in your USB flash stick now </b>        


             Please insert it now and select    <span color='"'blue'"'><b>Yes  </b></span> below.


              Selecting    <span color='"'red'"'><b>No</b></span>    will exit this application.

" $?
if [ $? != 0 ] ; then kill $mypid ; exit
fi
(
echo
sleep 10
) |
zenity --progress --pulsate --title="  DEVICE DETECTION    " --text "
 
                Your Inserted device is being detected    

                  This will take just a few moments.      

Do   <span color='"'red'"'><b>NOT</b></span>   attempt to view its contents while running this application.

                                  " --auto-close --auto-kill ;
DRIVES2=$(sfdisk -s | grep -e /dev/ | cut -d: -f1)
for file in $(echo $DRIVES2)
   do
        tmpstr=`echo $DRIVES1 | grep -v $file | head -1`
        if [ "$tmpstr" != "" ]
            then
                DEVICE="$DEVICE$file"                  
        fi
   done
        if [ "$DEVICE" == "" ];
then
     zenity --error --width=400  --title="         No New Device Detected!         " --text="
             <span color='"'red'"'><b>Oh dear! We have a problem!</b></span>

             There is no Device to select.

             This application will now exit.

If you wish to try again please restart the application."
     
   kill $mypid;   exit
         fi

###############
echo
zenity --info --text "The Detected Device is $DEVICE  "
exit 0
###############

« Last Edit: October 03, 2010, 12:45:17 PM by JohnBoy »

Offline Mark342

  • Sr. Member
  • ****
  • Posts: 334
Re: Code Problem?
« Reply #1 on: October 02, 2010, 06:16:33 PM »
Is sfdisk installed and in their $PATH?

If you change:
Code: [Select]
$(sfdisk -s | grep -e /dev/ | cut -d: -f1)to
Code: [Select]
$(fdisk -l | grep -o ' /dev/sd[a-z]' | cut -d' ' -f2)or
Code: [Select]
$(fdisk -l | sed -e '/ \/dev\//!d' -e 's|Disk \(/dev/sd[a-z]\).*|\1|')
Does it solve the problem?
(that is a lowercase L in "fdisk -l")
Anything worth doing is worth overdoing.

Registered Linux user #493318
Register yourself here: Linux Counter

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6849
  • MLU
Re: Code Problem?
« Reply #2 on: October 03, 2010, 03:21:23 AM »
Mark342,
                 Thank you for the response and the alternatives.

Is it somehow possible that sfdisk is in the path when the script is launched from a terminal, but not in the path when launched from a menu entry?

I'm not sure if I made it clear .....  the script will run perfectly when launched in some ways but throws this error when launched in others.

From what I can understand the script is good when launched from a terminal with
gksu /usr/bin/lusbc.sh
but fails from a menu entry with the same command.

In KDE all is OK with the menu entry
kdesu /usr/bin/lusbc.sh

sfdisk shows as being available and usable - even by a user.

.......  I wonder if grep and cut are available at the time, I never checked ......


regards

Offline critter

  • Full Member
  • ***
  • Posts: 220
Re: Code Problem?
« Reply #3 on: October 03, 2010, 03:29:45 AM »
Have you tried giving the absolute address of sfdisk?
That would eliminate the possibility that the path is not carried over to the command.
Motherboard   Gigabyte Z68X-UD3H-B3
Hard Drives      2 x Maxtor STM350032 500GB SATA
Memory      16GB RAM
Processor      Intel core i5 3.30GHz
Video         nVidia GeForce GT430
Sound      HDA Intel PCH
PCLinuxOS          KDE

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6849
  • MLU
Re: Code Problem?
« Reply #4 on: October 03, 2010, 03:35:09 AM »
Have you tried giving the absolute address of sfdisk?
That would eliminate the possibility that the path is not carried over to the command.

In the menu entry ...  as above .....

gksu /usr/bin/lusbc.sh

Is that what you mean?

Offline critter

  • Full Member
  • ***
  • Posts: 220
Re: Code Problem?
« Reply #5 on: October 03, 2010, 06:10:29 AM »
I meant

DRIVES2=$(/sbin/sfdisk -s | grep -e /dev/ | cut -d: -f1)

a sfsik is the file reported not being found
Motherboard   Gigabyte Z68X-UD3H-B3
Hard Drives      2 x Maxtor STM350032 500GB SATA
Memory      16GB RAM
Processor      Intel core i5 3.30GHz
Video         nVidia GeForce GT430
Sound      HDA Intel PCH
PCLinuxOS          KDE

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6849
  • MLU
Re: Code Problem?
« Reply #6 on: October 03, 2010, 06:51:51 AM »
I meant

DRIVES2=$(/sbin/sfdisk -s | grep -e /dev/ | cut -d: -f1)

a sfsik is the file reported not being found

Ah, sorry misunderstood.

UPDATE:
                 On further tests it appears that it is the 'cut' part of that command line that is throwing the errors.
It errors as if there are no options passed to it

Quote
cut: you must specify a list of bytes, characters, or fields

It only occurs in certain circumstances .....  such as if launched from a menu in LXDE-Mini or when using LXDE-Full as a live CD.
On a full install of LXDE I have no problem at all with the command or the script.

Most puzzling .........

EDIT:
            Will try putting the full paths of the commands into the line to see if corrects the problem.
Thanks for the suggestion   ;)
« Last Edit: October 03, 2010, 08:00:20 AM by JohnBoy »

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6849
  • MLU
Re: Code Problem?
« Reply #7 on: October 03, 2010, 12:44:59 PM »
Problem sorted ........  something different in the PATHS of LXDE-Mini and of the liveCD it seems.

Adding a PATH=<various paths>            line in the script seems to have sorted it.

Thanks for the help in sorting this.

regards.

Offline critter

  • Full Member
  • ***
  • Posts: 220
Re: [SOLVED] Code Problem?
« Reply #8 on: October 03, 2010, 12:55:24 PM »
Good news that you got it sorted :D
Hopefully we will see the results in the repos soon  ::)
Motherboard   Gigabyte Z68X-UD3H-B3
Hard Drives      2 x Maxtor STM350032 500GB SATA
Memory      16GB RAM
Processor      Intel core i5 3.30GHz
Video         nVidia GeForce GT430
Sound      HDA Intel PCH
PCLinuxOS          KDE

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6849
  • MLU
Re: [SOLVED] Code Problem?
« Reply #9 on: October 03, 2010, 01:24:33 PM »
Good news that you got it sorted :D
Hopefully we will see the results in the repos soon  ::)

That is the intention   ;)




regards.
« Last Edit: October 05, 2010, 09:12:32 AM by JohnBoy »