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.

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

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

Can you post the code you've tried, too?

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.

#!/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.

#!/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.

#!/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

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:

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:

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.

#!/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

You have an extra forward slash in your shebang after expect (highlighted in RED above)...

The reason is that line 11 is ignored and the shell (bash) doesn't know the "spawn"-command. This:

#!/path/to/some/shell

can only be used once to explicitly load some shell at the beginning of a script, so this line is valid only if it is the first line, otherwise not.

If you want to change the shell in between you have to call an external script, which can have its own first line. Like this:

#!/bin/bash

some_command

/path/to/script.ext

some_other_command

this is the content of /path/to/script.ext:

#!/bin/expect

spawn .....

Why don't you just tell us the whole story? Post your complete script here and tell us, step by step, what you want to do. It is easier to come up with a solution if we know the whole picture instead of having to debug one error after the other.

I hope this helps.

bakunin