Page 1 of 2

Script help - test user input yes/no [Solved :-) ]

Posted: 07 Dec 2013, 00:13
by Ed_P
I'm attempting to tailor a script @Fathom gave me a while back.

Code: Select all

#!/bin/sh
echo -en "Did you do the SU command?\nPress Enter if you did\n"
read
cp -a /home/guest/cleanup /mnt/live/
My question is how do I test for a negative answer and then exit the script?

Re: Script help

Posted: 07 Dec 2013, 03:31
by Slaxmax
Example

Code: Select all

#!/bin/sh
echo "blablablabla ?"
select yn in "Yes" "No"; do
    case $yn in
        Yes ) YOUR CODE HERE; break;;
        No ) exit;;
    esac
done 

Re: Script help

Posted: 07 Dec 2013, 04:55
by Ed_P
Thanks @Slaxmax. Do I not need a Read after the Echo?


-update-

Wow!! :Yahoo!: No, I do not need the Read. Cool!! Thanks @Slaxmax.

Re: Script help

Posted: 07 Dec 2013, 17:37
by Ed_P
Ok, lost again.

Code: Select all

#!/bin/sh
echo -en "Did you do the SU command?\n"

select yn in "Yes" "No"; do
    case $yn in
        Yes ) cp -a /home/guest/cleanup /mnt/live/;
              break;;
        No ) break;;
    esac

sh /home/guest/touchpad.sh
synclient
echo -en "Did synclient run?\n"
read

exit
done
If the answer is No I simply want to exit the case command not the script.

Re: Script help

Posted: 07 Dec 2013, 19:21
by Slaxmax
EdP wrote:Ok, lost again.

Code: Select all

#!/bin/sh
echo -en "Did you do the SU command?\n"

select yn in "Yes" "No"; do
    case $yn in
        Yes ) cp -a /home/guest/cleanup /mnt/live/;
              break;;
        No ) break;;
    esac

sh /home/guest/touchpad.sh
synclient
echo -en "Did synclient run?\n"
read

exit
done
If the answer is No I simply want to exit the case command not the script.
delete the second break

Re: Script help

Posted: 07 Dec 2013, 19:45
by Ed_P
Slaxmax wrote: delete the second break
Yup, I figured it out also. Then I replaced it with exist again, that's really what I want to script to do, not either / or but both in root mode and nothing if in guest mode.

Thanks for helping me @Slaxmax.

Re: Script help

Posted: 07 Dec 2013, 22:35
by tome
this can be done automatically at start (etc/rc.d/rc.local) or probably by cliexec cheatcode

Re: Script help

Posted: 08 Dec 2013, 14:21
by brokenman
If i understand you are tired of putting in commands only to find that you did not elevate your privileges to root before doing so. This means you have to then elevate to root and retype the command? Is this the real problem?
If it is just for one script then this will suffice.

Code: Select all

if [ $(whoami) != "root" ]; then
    echo "Did you SU?"
    read sued
    if [ "$sued" != "y" ]; then exit; fi
fi
This will only ask you the question are running as guest. If the user does not press the 'y' key it will exit. I don't see the need for a case here.

Re: Script help

Posted: 09 Dec 2013, 00:43
by Ed_P
tome wrote:this can be done automatically at start (etc/rc.d/rc.local) or probably by cliexec cheatcode
Part of it yes, but not the part that requires root privileges. Or can root mode be achieved via a script command?
brokenman wrote:If i understand you are tired of putting in commands only to find that you did not elevate your privileges to root before doing so. This means you have to then elevate to root and retype the command? Is this the real problem?
With the current script unless I scroll back I do not see the error msg the cp command fails with when run as guest. If I can become confident the synclient changes are executing I won't need to run the synclient command to list everything and will see the cp error if run as guest. Other options would be to test if the cp command issued an error msg, the script programmatically switching to root mode, being able to display specific synclient settings rather than all of them, etc.
brokenman wrote:If it is just for one script then this will suffice.

Code: Select all

if [ $(whoami) != "root" ]; then
    echo "Did you SU?"
    read sued
    if [ "$sued" != "y" ]; then exit; fi
fi
This will only ask you the question are running as guest. If the user does not press the 'y' key it will exit. I don't see the need for a case here.
Thanks @brokenman.

Re: Script help

Posted: 09 Dec 2013, 17:02
by tome
Part of it yes, but not the part that requires root privileges. Or can root mode be achieved via a script command?
rc.local and cliexec are executed as root

I need also help

Code: Select all

echo "    Mounting iso or xzm from a url without downloading       "
echo "        Paste your url and press Enter      "

hpoint=/mnt/httpfs2
xls=`ls $hpoint`

read bup
httpfs2 "$bup" $hpoint

#to do
#How to bind /mnt/httpfs2, "/" and module.xzm (ls $hpoint) to /mnt/httpfs2/module.xzm? (or another, the easiest way to do this)

#yls=`$hpoint/$xls`

#mkdir /mnt/$xls
#mount -o loop $yls /mnt/$xls

Re: Script help

Posted: 09 Dec 2013, 18:07
by Ed_P
tome wrote:
Part of it yes, but not the part that requires root privileges. Or can root mode be achieved via a script command?
rc.local and cliexec are executed as root
!!! Wow!!

In looking at the cheatcode it shows cliexec=my_script, how does it know where "my_script" is? Would I use cliexec=/home/guest/test.sh or cliexec=/dev/sdb2/home/guest/test.sh ? Or does the script have to be in the rc.local folder to be executed by cliexec?

Re: Script help

Posted: 09 Dec 2013, 18:35
by tome
it doesn't matter for cliexec=. You can edit and add this to rc.local:
cp -a /home/guest/cleanup /mnt/live/

Re: Script help

Posted: 09 Dec 2013, 18:46
by Ed_P
:( I can't find rc.local. Even when logged in as root!!

Re: Script help

Posted: 09 Dec 2013, 19:16
by tome
etc/rc.d/rc.local

Re: Script help

Posted: 16 Dec 2013, 04:41
by Ed_P
Thank you @Tome. I've been busy and haven't got back to this but I will.



-update-

I found the file, made the change but couldn't save it. :x Signed off as guest and back on as root, found the file, made the change, saved it :Yahoo!: , rebooted and voila!! It worked.

Thank you @Tome. :beer: