Wait command in DCL before executing next command - terminal

Is there a command in DCL that will wait for a specified amount of time before executing the next command. I am making a simple command file that will ping a user specified IP Address, wait 5 seconds then repeat the ping process.
Currently I have managed to ask the user for an IP Address which is then pinged.
$ INQUIRE PINGTEST "Enter IP Address"
$ TCPIP PINGTEST
$ <wait command>
$ <repeat TCPIP PINGTEST>

Based on the information provided by #Svend DCL supports a WAIT command formatted as WAIT delta-time
So for example if I wanted to wait 5 seconds before executing the next command the code would be as follows:
$ INQUIRE PINGTEST "Enter IP Address"
$ TCPIP PINGTEST
$! WAIT time format hour:minute:second.hundredth
$ WAIT 00:00:05
$ TCPIP PINGTEST

Related

Minicom script called from jenkins failing on exit of '! killall -9 minicom'

I managed to make a script which sends a few commands via minicom and stores them on output.txt. The script which calls minicom, is called dut.sh
#!/bin/bash
echo "Setting up DUT"
stm_armv7 -print "DUT"
stm_armv7 -dut
echo "wait 30s"
sleep 30s
stty -F /dev/ttyACM0 115200 cs8 -cstopb -parenb
rm /home/fsnk/scripts/serial-com/output.txt
export TERM=linux-c-nc
minicom -b 115200 -D /dev/ttyACM0 -C /home/fsnk/scripts/serial-com/output.txt -S /home/fsnk/scripts/serial-com/serial -o
echo "wait another 5s"
sleep 5s
stm_armv7 -ts
So on minicom command, i give another file called just serial which has some runscript code.
# UNIX login script.
# Can be used to automatically login to almost every UNIX box.
#
# Some variables.
set a 0
set b a
print Trying to Login..
# Skip initial 'send ""', it seems to matter sometimes..
send ""
goto login
login:
if a > 3 goto failed1
expect {
"ogin:" send "root"
"assword:" send ""
timeout 5 goto loop1
}
goto loop1
loop1:
send "systemctl is-system-running --wait"
sleep 3
# Send command not more than three times.
inc b
if b > 3 goto failed1
expect {
"\nrunning" goto success1
break
"degrading" goto success2
break
timeout 5 goto failed2
}
success1:
print \nSuccessfully received running!
! killall -9 minicom
exit
success2:
print \nSuccessfully received degrading!
! killall -9 minicom
exit
failed1:
print \nConnection Failed (wrong password?)
! killall -9 minicom
exit
failed2:
print \nMessage sending failed. Didn't receive anything!
! killall -9 minicom
exit
The command ! killall -9 minicom kills the minicom terminal based from its manual. As i mentioned it earlier, when i run this locally, or when i call the script via ssh from my local machine, it runs okay. The problem occurs when i run this from jenkins.
The output.txt file gets created, but remains empty while on Jenkins, i receive a minicom message like this:
Setting up DUT
wait 30s
Welcome to minicom 2.7
OPTIONS: I18n
Compiled on Apr 22 2017, 09:14:19.
Port /dev/ttyACM0, 16:30:57
Press CTRL-A Z for help on special keys
/home/fsnk/scripts/serial-com/dut.sh: line 12: 5639 Killed minicom -b 115200 -D /dev/ttyACM0 -C /home/fsnk/scripts/serial-com/output.txt -S /home/fsnk/scripts/serial-com/serial -o
wait another 5s
Finished: SUCCESS
After the message Press CTRL-A Z for help on special keys i would expect it to login to the board (no password, only root user) and run systemctl is-system-running --wait. All the output must be on output.txt
Again, this works just as expected when run manually or trigerred from my machine via SSH, but when trigered from Jenkins (Added a build step execute shell which tries to SSH and launch the script) it doesnt work.
At this point i feel like its a minicom issue, in that case, i welcome any solution with screen
I believe it is because the killall causes minicom to return an error code to the operating system, which Jenkins evaluates and so considers it a failure. You could add a try/catch block to mark the build unstable or success if that is the cause.

How to exit command if command does not output anything for 10 seconds?

I want to ssh IP obtained in varible "a". this works fine if everything is ok.
But if my command "commandToGetIP" get stuck in network or by any chance it will not return any output my script will go in hung state.
Now what i need to get is this command "commandToGetIP" should wait only for 10 sec and come out giving some message
a=commandToGetIP <DeviceID>
ssh $a
I want to ssh IP obtained in varible "a". this works fine if everything is ok.
But if my command "commandToGetIP" get stuck in network or by any chance it will not return any output my script will go in hung state.
Now what i need to get is this command "commandToGetIP" should wait only for 10 sec and come out giving some message
So, bash has a built in command to timeout another command. If the command takes too long, timeout will kill it with exit code 143. Using this information, I am checking to see if the exit code was not 143 before performing the ssh command. Otherwise, it'll do whatever you want it to do when commandToGetIP takes too long.
timeout 10 commandToGetIP <DeviceID> | read ip
result=$?
if [ "$result" != "143" ]; then
ssh $ip
else
# What we do if it times out
fi

Terminate Curl Telnet session in bashscript

Working on automating telnet connectivity from various hosts running the script from specified host with curl telnet call.
However as are aware for telnet once we get connected status for any hosts we have to pass an escape character to terminate the telnet sessions, but in bash script I need to terminate the session as soon as we get Connected/Refused response from the target endpoint or after some seconds of running the telnet session .
PFB Script where telnet connectivity is checked through Curl call, so I need is there anyway in curl that we can terminate the telnet session in curl as soon as we get the response or terminate the session in some milliseconds/seconds.
Code:
#!/bin/bash
HOSTS='LPDOSPUT00100 LPDOSPUT00101'
for S in ${HOSTS}
do
echo "Checking Connectivity From Host : ${S}"
echo ""
ssh -q apigee#${S} "curl -v telnet://${TargetEndPoint}:${Port}"
done
You could run it in the timeout command to make it terminate after a certain amount of time.
ssh -q apigee#"$S" "timeout 5s curl -v telnet://${TargetEndPoint}:${Port}"
would terminate it after 5 seconds if it hadn't already exited on its own.
Perhaps curl isn't the right tool for this job though. Have you considered using nc instead?
ssh -q apigee#"$S" "nc -z ${TargetEndPoint} $Port"
will likely do what you want.

Telnet : connect, send command and exit in just one line

I try to use telnet in a script (to be use in python program). I want to do the connection, send a command, and exit the connection in juste one line. The command i want to send is to start a program on a remote machine but I d'ont want to wait the end of this program to exit the telnet connection.
I try to do : "echo myCommand | netcat 192.168.1.50 23" but it waits the end of the program.
thanks for your help
Use bash builtin tcp socket feature:
echo yourCommand >/dev/tcp/192.168.1.50/23

shell script that notes timestamps and runs a command every 15min and sends the result to a .txt

Doin a experiment on Tor and messuring the performance of the network. I would need a script that notes timestamps and runs a command "proxychains iperf3 -c "ip address" and send the result to a .txt . I need to run this every 15min 24/7. It´s getting annoying to stay awake. Thansk !
You can start with something like the following:
touch mylogfile.txt
while true
do
proxychains iperf3 -c "ip address" >> mylogfile.txt
sleep 900
done
if you want to run it without crontab

Resources