linux wait command only proceed if previous job successful putty - linux

Im an end user that has access to Putty in order to run selective scripts on our server as they would run during our overnight batch process.
Some of these I run in sequence using
run_process.ksh kj_job1 & wait; run_process.ksh kj_job2
However kj_job1 can fail and kj_job2 would still run. Id like a way for kj_job2 to only proceed if kj_job1 was completed succesfully but i cant find a guide online to walk me through what i need to do.
My knowledge in this area is limited, i simply navigate to the directory where we have the file run_process.ksh and then add the job name i want to run. I recently found out about the & wait command in order to run strings and the () s i can run things in parallel.
Any help is apprecaited.

Related

Show progress in a azure-pipeline output

so I have my computer set up as an agent pool in azure-devops. I'm creating a test for latency so the developers can use it in their CI, the script runs in python and test various points in a system I have set up for the company which is connected to the cloud, it's mainly for informative purposes. When I run the script I have to wait some time, so the system I have connected goes through its normal network cycle inspecting all the devices in the local network, not very important for que question, however when I'm waiting I show in the terminal a message with "..." going from "." to ".." to "...", just to show the script didn't crash or anything.
the python code looks like this and works just fine when I run it locally:
sys.stdout.write("\rprocessing queue, timing varies depending on priority" + ("."*( i % 3 + 1))+ "\r")
sys.stdout.flush()
however the output shown in the azure pipeline shows all of the lines without replacing them. Is there a way to do what I want?
I am afraid showing progress is not supported in azure pipeline. Azure pipeline log console isnot user interactive. It just capture the agent machine terminal outputs.
You might have to use a simpler way to indicate that the script is now executing and not finished yet. For simple example:
sys.stdout.write("Waiting for processing queue ..." )
You can report this problem to microsoft development team. Hope they find a way to fix this in the future sprint.
I have seen it once but never actually used it myself, this can be done in both bash and PowerShell, not sure if this works inside a Python script, you might have to call bash/PowerShell from within your Python script.
It is possible to set a progress value in percent that is visible outside of the log, but as I understand it this value is step-spefific, meaning it only applies to the pipeline step you're currently in. You could drag the numeric value (however many percent) along into the next step, but the progress counter would then again show up in the next step. I believe it is not possible to have a pipeline global display of a progress.
If you export a progress value it will show up beside the step name in the left hand side step list.
This setting of a progress (also exporting one variable from one step to another, which is typically done that way) can be done by echoing special logging commands. There's a great description to be found here: Logging commands
What you want to do is something just as it is shown as an example on the linked page:
echo "Begin a lengthy process..."
for i in {0..100..10}
do
sleep 1
echo "##vso[task.setprogress value=$i;]Sample Progress Indicator"
done
echo "Lengthy process is complete."
All of these special logging commands start with ##vso[task... The VSO is a relict to the time when Azure DevOps was called Visual Studio Online.
There are a whole bunch of them, but most of the time what you really need is exporting variables from one build step context to another, which is done with ##vso[task.setvariable]value

How to catch and act when prompted for user input in shell script?

I have a working shell script which calls another shell script to perform some action on some processes running on the server. This inner shell script sometimes prompt to enter the userid and password. If this happens I want to come out this inner script and want to perform kill -9 for the process. Can anyone please suggest on how to achieve this?
One more point, whatever my shell scripts does, I am recording this in a log file,so I assume when script prompts to enter userid and password, this info also get recorded in the log.So is their should be a way to check this in the log file.
I am working on Linux OS. Please check and advise.
You can kill your child script
after some timeout:
( cmdpid=$BASHPID; (sleep 10; kill -9 $cmdpid) & exec my-child-script )
In this case you will kill my-child-script after given period of time (10 sec).
You can't (easily) detect if you script is waiting for input (on standard input), the only working method is to use strace/ptrace, but it's too complex
and I don't think it's really worth it. The timeout-based approach seems to be by far more natural.
You can find here
some additional examples of this approach in this question:
Bash script that kills a child process after a given timeout
Regarding log files:
You can extract data from your log files using grep/sed. To make the answer more concrete, we need some extra data.

Ping remote arbitrary command execution on linux

I'm trying to execute code on a remote machine (virtual), which runs a webserver with a single POST form, intended to do a simple ping. On the other side is the following script (part of it):
exec("/bin/ping -c 4 ".$_POST["addr"]);
"addr" is where the data entered in the POST form goes. So basically it calls /bin/ping and appends whatever data I enter. The question is how can I leverage this to get a shell? I think that since the ping command runs with root privileges it should be fairly easy but I'm still new to this game and couldn't find any useful info on how to do this. Help will be very much appreciated :)

Is it possible to incorporate an environment variable into a ruby script for Calabash?

I am testing a feature on an app that requires the user to be a certain age. The only time you see the prompt that asks for your age is once you open the app for the first time and once you log out of the app. I don't want my test to only go through my steps to log in and then log out to be able to see this prompt, but I also don't want to manually reset the data in between tests either. Isn't this why we write scripts? Anyways, before I launch the test, I use the environment variable RESET_BETWEEN_SCENARIOS=1 cucumber features/my_feature.feature. Is there a way that I can use this variable INSIDE of my step definition so that it resets the data on its own once I run the script?
I'm not familiar with Calabash, but it appears to be using cucumber. If that is the case, you could handle the action in a before or after hook which would run before or after each scenario.
Within the features/support folder, add a file hooks.rb
Before() do
if ENV['RESET_BETWEEN_SCENARIOS'] == '1'
#code to reset data
end
end
This could also be run after the scenario by using After() do. The same if/then could be used within a scenario step as well.

Does ant sshexec task return when command it's executing returns or before?

Basically I've got 2 sshexec tasks in an ant target, one after the other. The first one launches a message sender on one machine, and the second one launches a message receiver on a different machine.
I was assuming that the sshexec task will issue the command to run the message sender, and then return while the sender is running, and then the following sshexec task would start the receiver, and thus both sender and receiver would be running in parallel, which is what I hope to achieve, but I'm not sure if this is actually the case, or if in fact the first task will only return when the sender returns, and thus the receiver will only get started after the sender has finished executing.
The sshexec task page doesn't seem to offer much info, and I'm somewhat new to mac ( the commands are being issued on mac minis running macos 10), so any help would be greatly appreciated, thanks!
<!--start sender-->
<sshexec host="${ip.client3}"
username="${username}"
password="${userpassword}"
trust="true"
command="./sender"
/>
<!-- start receiver-->
<sshexec host="${ip.client4}"
username="${username}"
password="${userpassword}"
trust="true"
command="./receiver "
/>
<sshexec> task will return after the remote command returns.
If you just want the two commands to start at the same time, you can use <parallel> task. Any task nested in <parallel> task will run "at the same time" by multi threading. However, in this way, <sshexec> still need to wait for the two commands to return.
If you just want your ant script to launch those two commands and continue building without waiting for remote commands to return, you may use things like nohup in your commandline.
I am not sure if nohup works, because when I run a remote command from a ssh terminal with nohup like this:
nohup command & [ENTER]
I have to press enter again before I start to use the same terminal to do something else.

Resources