0

I have the following scenario. I have a shell script that is generated automatically, that I want to run. The general format of the script looks something like this:

 #!/bin/sh

 command_1 #something like mkdir dir1 or chmod -R 775 dir1, you get the idea 
 command_2
 ...
 ...
 command_n

Like I said the script will be automatically generated in a way that I don't have much control of the commands that are written in the script (the purpose of the script is to use it for fuzz testing, so it makes sense). The problem is that some commands require some sort of user input (for example "chfs --some arguments" will sometimes prompt me for the root password), and therefore the script will not pass to the next command until it gets the proper input.

So, my question is: Is there a way to skip the commands that require user input when they are met in such a script, so that the script finishes and executes all the other commands? Any idea is greatly appreciated.

1
  • 1
    Depends on the method of requesting input. does ./script.sh < /dev/null help? Commented Sep 23, 2013 at 21:19

2 Answers 2

1

You can use expect script to work around this, something like this

    spawn /bin/bash yourscipt.sh
    expect "password:"
    # Send the password, and then wait for a shell prompt.
    send "xxxxx\r"

Here XXXX isyour password.

Sign up to request clarification or add additional context in comments.

Comments

1

Lets say your script requires a user to enter a choice interactively. User press y then again it askes user name. User enter his name and then script continues.

Enter choice (y/n):_

Enter name :_

So you can pass inputs by preparing an input file with choices written in each line.

content of input file :

y

Inderdeep

And run the script as : cat inputfile | ./script

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.