User Input Automation without Spawn


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting User Input Automation without Spawn
# 1  
Old 05-15-2012
User Input Automation without Spawn

Hello All!

I am attempting to create a shell script that will execute another shell script (mandatory by 3rd party software I'm attempting to automate).

What I want to do is simply this, once the shell script is run, it will execute the other shell script (I have that done fine and working), wait 15 seconds, and input a series of commands, with waiting time inbetween, and then exit it.

The program I am using is SteamCMD, and I am automating the server creation process. They have a scripting method included that will allow you to execute commands from a .txt file, but due to the program being new, there are bugs and I am required to wait some time between each command or else it will fail.

I attempt to do this script using spawn and expect, however that did not work. Any help will be much appreciated.
# 2  
Old 05-15-2012
Please give us more information: Your OS and version, the shell you use and either your expect code with the error message or the code you wrote that you said worked fine and the SteamCMD so we can understand a bit, so far I understood you were trying to run an expect script on the same box (not a remote...) Is that right?
P.S.
Dont forget to put your cade and data between code tags, thanks
# 3  
Old 05-15-2012
Hello, thanks for your prompt response, sorry I excluded that information. I am using Ubuntu 12.04 64 bit for this task.

developer.valvesoftware.com/wiki/Counter-Strike:_Global_Offensive_Dedicated_Servers#Downloading_Counter-Strike:_Global_Offensive

this is a link to the software Im attempting to automate. I tried using "spawn" and "expect" however those did not work, so I'm unsure which direction to go now.

---------- Post updated at 03:34 PM ---------- Previous update was at 03:12 PM ----------

heres a screenshot of how it looks

Image

Last edited by Scrutinizer; 05-15-2012 at 04:54 PM.. Reason: formatting
# 4  
Old 05-15-2012
Can you post the code you've tried, too?
# 5  
Old 05-15-2012
I have tried a lot of different variations, unfortunately I didn't keep a full log of them all, but I will paste what I have.

Code:
#!/bin/bash

STEAMEXE=steamcmd ./steam.sh
sleep 15
send "login username password"

I've tried this same variation with spawn STEAMEXE=steamcmd ./steam.sh, however it will not allow that to be spawned, so I cannot follow through with the expect script.

Code:
#!/bin/bash
echo "CS:GO Server Install Script"
cd /home/csgoinstall
BASEDIR=$(dirname $0)
echo $BASEDIR
echo -e "// csgo_ds.txt
//
login username password
force_install_dir $BASEDIR
app_update 740 validate
quit" > csgo.txt
sleep 3
STEAMEXE=steamcmd ./steam.sh +runscript csgo_ds.txt
sleep 60

this works, however it does not allow for delays inbetween the command, as this is how SteamCMD does their own scripting.

Code:
#!/usr/bin/expect

spawn STEAMEXE=steamcmd ./steam.sh

this does not work at all

---------- Post updated at 06:12 PM ---------- Previous update was at 04:05 PM ----------

also here is a link to the steam.sh script that is being run

Moderator's Comments:
Mod Comment Scott - Removed Pastebin link. Please post in the forums.

Last edited by bakunin; 05-15-2012 at 07:56 PM..
# 6  
Old 05-15-2012
Quote:
Originally Posted by foghsho
Code:
STEAMEXE=steamcmd ./steam.sh +runscript csgo_ds.txt
sleep 60

this works, however it does not allow for delays inbetween the command, as this is how SteamCMD does their own scripting.
Actually i don't think this will run at all. The line "STEAMEXE=..." just defines a variable named "STEAMEXE" with the content of the first word behind the equal sign. Then the script waits for 60 seconds.

If this is the command you want to run do like:

Code:
STEAMEXE="steamcmd ./steam.sh +runscript csgo_ds.txt"   # load the variable with the WHOLE string

$STEAMEXE                                               # execute the variables content
sleep 60                                                # then wait 60 seconds

If "steamcmd" is another variable you will have to prepend "$" in front to assign "$STEAMEXE" with its content and something added. See the following example, which shows the mechanism:

Code:
a="xxx"                      # assign a variable
echo $a                      # print this variable
b="$a yyy"                   # create a new variable which contains the first one
echo $b                      # print the new variable

Furthermore: Unix is case-sensitive for the most part. Variables "A" and "a" are distinct!

I hope this helps.

bakunin
I hope this helps.
# 7  
Old 05-15-2012
Code:
#!/bin/bash
echo "CS:GO Server Install Script"
# Absolute path to this script, e.g. /home/user/bin/foo.sh
SCRIPT=`readlink -f $0`
# Absolute path this script is in, thus /home/user/bin
SCRIPTPATH=`dirname $SCRIPT`
echo $SCRIPTPATH

cd /home/csgoinstall/
STEAMEXE="steamcmd ./steam.sh"
#!/usr/bin/expect/
spawn $STEAMEXE

I'm running into an issue now of :
./jeff2.sh: line 12: spawn: command not found
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

User input and run awk using the input

I am trying to allow a user to enter in text and then store that text in a variable $gene to run in an awk command in which those values are used to run some calculations. I am getting syntax errors however, when I try. Thank you :). The awk runs great if it is a pre-defined file that is used,... (7 Replies)
Discussion started by: cmccabe
7 Replies

2. Shell Programming and Scripting

Hide the output of spawn ssh user@server

Hi All, I have written one script, which is connecting 3 diffrent servers and executing script placed on those. It is smthing like: spawn ssh user@server1 expect "*? assword:" send "pw \r" expect "$" send " sh ./filename1 \r" expect "$" expect eof spawn ssh user@server2 expect "*?... (7 Replies)
Discussion started by: KDMishra
7 Replies

3. Shell Programming and Scripting

Script interacts with user , based on user input it operates

i have a script which takes input from user, if user gives either Y/y then it should continue, else it should quit by displaying user cancelled. #!/bin/sh echo " Enter your choice to continue y/Y OR n/N to quit " read A if then echo " user requested to continue " ##some commands... (7 Replies)
Discussion started by: only4satish
7 Replies

4. Shell Programming and Scripting

How to get the user input recursively until the user provides valid input

Hi, echo "Enter file name of input file list along with absolute path : " read inputFileList if then for string in `cat inputFileList` do echo $string done else echo " file does not exist" fi From the above code, if the user enters a invalid file... (1 Reply)
Discussion started by: i.srini89
1 Replies

5. Shell Programming and Scripting

user input in perl?

Please tell me how to write a perl script that asks the user to enter words and that passes them to a variable. In bash, the "read" command would achieve such user interaction. #!/bin/bash read -p "Enter files: " vFiles However, I am looking for perl version of something equivalent... (2 Replies)
Discussion started by: LessNux
2 Replies

6. Programming

spawn a process with a different user

Hello Everyone: I have the following code int main() { system("/usr/OtherUser/bin/runX"); return 0; } runX must be executed with privileges from another user, how could I do that? I know the password for such user. Thanks in advance (8 Replies)
Discussion started by: edgarvm
8 Replies

7. Shell Programming and Scripting

Bash user input

Hi all, I currently have a script which uses read -p for user interaction. e.g. read -p "New user? " user Is it possible to have it so if the user enters nothing and just presses return it can resort to a specified value instead? Thanks! :) (5 Replies)
Discussion started by: JayC89
5 Replies

8. Shell Programming and Scripting

Need help with user password automation

Hello, I need some assistance in trying to figure out the best way to automate user account password resets. The environment is a mix of 2000 HP-ux, aix, linux, and sunos boxes. The security specs are to reset pw's every 90 days. Most boxes are only accessible from within a current ssh... (2 Replies)
Discussion started by: deviousdoses
2 Replies

9. Shell Programming and Scripting

Reading input from user

how do we read input from a user e.g i want to ask a user to enter 6 sets of numbers how do i control information from the user? i have this....... #!/bin/bash echo "Please enter six numbers" read number echo $number >> file1 but this stops after the first number..how can i... (2 Replies)
Discussion started by: vadharah
2 Replies

10. Shell Programming and Scripting

Getting user input

I am trying to create a shell (ksh) which has two "read" commands, one which reads a line from a file and another which is inside a loop that reads user input from a keyboard. However, the "read" command inside the loop uses the input from the file and it does not get the user input from keyboard.... (3 Replies)
Discussion started by: stevefox
3 Replies
Login or Register to Ask a Question