Confirming command


 
Thread Tools Search this Thread
Operating Systems AIX Confirming command
# 1  
Old 02-13-2011
Confirming command

Guy's

I'm trying to create script to execute some critical commands in AIX
like the below ...


stopsrc -s qdaemon
stopsrc -s sshd
stopsrc -s lpd
stopsrc -s nfsd

I want between each command to ask me like this

" are you sure to stop qdaemon "
" are you sure to stop ssh"
" are you sure to stop lpd"
" are you sure to stop nfsd"

can any one advice in this regard how can I mention that to be asked after execute each command and to press Y to Continue or N to Cancel ...

Smilie

Last edited by Mr.AIX; 02-13-2011 at 06:35 PM..
# 2  
Old 02-14-2011
Create a function in your script, e.g...
Code:
function sure {
    echo Confirm Command: $*
    unset REPLY
    until [[ $REPLY = "Y" ]] || [[ $REPLY = "N" ]]
    do
        printf 'Are you sure? [Y/N]: '
        read
    done
    if [[ $REPLY = "Y" ]]
    then
        echo Executing Command: $*
        $*
    fi
}

...and use it like this...
Code:
sure stopsrc -s qdaemon
sure stopsrc ...

# 3  
Old 02-14-2011
Sorry .. Can you please clarify where exactly I have to mention the command as I got nothing?
As I mentioned the command replacing of $* but still is not asking me Y or N

--------------------------------------------
Code:
function sure {
echo Confirm Command: $*
unset REPLY
until [[ $REPLY = "Y" ]] || [[ $REPLY = "N" ]]
do
printf 'Are you sure? [Y/N]: '
read
done
if [[ $REPLY = "Y" ]]
then
echo Executing Command: $*
$*
fi
}

-----------------------------------
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 02-14-2011 at 07:05 AM.. Reason: code tags, please!
# 4  
Old 02-14-2011
Note sure why you are having any difficulty. Here's an example...
Code:
$ cat s1.sh
#!/bin/sh

function sure {
    echo Confirm Command: $*
    unset REPLY
    until [[ $REPLY = "Y" ]] || [[ $REPLY = "N" ]]
    do
        printf 'Are you sure? [Y/N]: '
        read
    done
    if [[ $REPLY = "Y" ]]
    then
        echo Executing Command: $*
        $*
    fi
}

sure who
sure date

$ sh s1.sh
Confirm Command: who
Are you sure? [Y/N]: n
Are you sure? [Y/N]: N
Confirm Command: date
Are you sure? [Y/N]: Y
Executing Command: date
Tue Feb 15 09:16:01 WAST 2011

$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Another one line command where I'd like to determine if Ubuntu or Red Hat when running command

Hello Forum, I'm making very good progress on my report thanks to the very helpful people on this forum. I've been able to successfully create my report for my Red Hat servers. But I do have a few ubuntu servers in the mix and I'd like to capture some data from them when an ssh connection is... (8 Replies)
Discussion started by: greavette
8 Replies

2. Shell Programming and Scripting

Confirming validity of programming language tools

so i have scripts that get run in ways similar to this: cat script.pl | perl - $1 $2 $3 cat script.rb | ruby - $1 $ 2 $3 my question is, how can i verify that that the "perl" or "ruby" or "python" tool being run on the box is actually a legit tool? meaning, someone may move the tool from... (2 Replies)
Discussion started by: SkySmart
2 Replies

3. Shell Programming and Scripting

Confirming a string

Hi Guys, I have files that are sent to me in this format: Copy of USer Database updated 23 JANUARY 2013.csv I am developing a script to load these files to my database automatically whenever I get these files: How do I verify these files in an if statement if I do have these files? ... (5 Replies)
Discussion started by: Phuti
5 Replies

4. Shell Programming and Scripting

Multiple command execution inside awk command during xml parsing

below is the output xml string from some other command and i will be parsing it using awk cat /tmp/alerts.xml <Alert id="10102" name="APP-DS-ds_ha-140018-componentFailure-S" alertDefinitionId="13982" resourceId="11427" ctime="1359453507621" fixed="false" reason="If Event/Log Level(ANY) and... (2 Replies)
Discussion started by: vivek d r
2 Replies

5. UNIX for Dummies Questions & Answers

passing command output from one command to the next command in cshell

HI Guys, I hope you are well. I am trying to write a script that gets executed every time i open a shell (cshell). I have two questions about that 1) I need to enter these commands $ echo $DISPLAY $ setenv $DISPLAY output_of_echo_$display_command How can i write a... (2 Replies)
Discussion started by: kaaliakahn
2 Replies

6. IP Networking

Confirming Successful Server/Device Reboot

Hello I've created a list with IP address to servers/devices I would like to reboot and have logged the following to the /tmp before: -netstat -nrv -/etc/rc2.d/netmask -/etc/rc2.d/defaultrouter -ifconfig -a I would like to confirm that nothing changed after the reboot. I know this can be... (0 Replies)
Discussion started by: ravzter
0 Replies

7. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

8. Shell Programming and Scripting

Confirming Remote Copy

Hey guys. I'm knocking up a script, a part of which will be copying some pretty large files to some remote servers. With the size of the files I need to make sure that they don't lose any data / corrupt on the way (it's unlikely, but these are business critical). Obviously I could use the... (2 Replies)
Discussion started by: dlam
2 Replies

9. Shell Programming and Scripting

Confirming Syntax - IF statement.

Hi All, Has been a while since I was last on, so I hope everyone has been doing fine. ;) Would like to know if the below IF statement syntax is correct for a ksh environment. It's been pushed into live as someone had deleted the development copy(!); not withstanding that, the statement now... (3 Replies)
Discussion started by: Cameron
3 Replies

10. SuSE

inconsistent ls command display at the command prompt & running as a cron job

Sir, I using the following commands in a file (part of a bigger script): #!/bin/bash cd /opt/oracle/bin ls -lt | tail -1 | awk '{print $6}' >> /tmp/ramb.out If I run this from the command prompt the result is: 2007-05-16 if I run it as a cron job then... (5 Replies)
Discussion started by: rajranibl
5 Replies
Login or Register to Ask a Question