Can saltstack use same jid for multi job? - salt-stack

I intend to get all results of multi jobs by looking up just one jid.
for example:
Two cmd.run which will be run:
$ salt 'a' cmd.run 'echo "job 1"' jid=1
$ salt 'b' cmd.run 'echo "job 2"' jid=1
Then i would like to get consolidated result from jid 1.
Is it possible?

As far as i know this is not possible. A jid is a unique id for a certain job.
In case the command that you want to execute is something generic that can be executed on host a and b and will return for example "job 1" or "job 2" based on host information you can do something like this:
salt -C 'L#a,b' cmd.run C:/get_result.bat
If get_result.bat is returning "job 1" or "job 2" based on host information.

Related

UNIX - testing for file across ssh and returning True on original host

Need to check for distribution of a file in an array programmatically. Logging into a master server and then would like to check for file on workers using simple ssh. So far I have:
ssh $HOSTNAME "[ -e '$HOSTNAME:/directory/filename' ] && echo 'Exists'"
Based on some of the logging output, I know the ssh is successful, but how can I get the test to return a message to the master server? Running the above returns nothing.
SSH will exit with the same exit code as the command that you run on the remote host. If that command is a test, then the exit code will match what you would normally expect from a test.
I would suggest the following:
Simplify your command to only run the test over SSH
Run the echo on your local machine
It doesn't seem correct that you have $HOSTNAME: in front of your path.
ssh "$HOSTNAME" "test -e '/directory/filename'" && echo 'Exists'
I personally find if statements to be much more easily understandable, which is an optional change if you are willing to go that route:
if ssh "$HOSTNAME" "test -e '/directory/filename'"; then
echo "Exists"
else
echo "Does not exist" >&2
exit 1
fi

How to filter the Running jobs in a particular server in Autosys..?

I am new to Autosys. Is it possible to find all the running jobs on a particular server in Autosys. (Like what we are doing in TWS or other monitoring tools).
The command to show running jobs on a specific server is this:
autorep -M servername -d
- note that the servername value has to match exactly what's in the JIL.
Also the output isn't detailed like you'd get from "autorep -d -j jobname" - but then it does what you asked!
If you want the job detail you might want to use the previous suggestion. Or you could use autorep -M as I suggested to get the running jobs and pipe that list through autorep -j to get detail just for those specific jobs.
Yes you can find out the list of jobs running in autosys. Put the command in GUI as autorep -j % | find " RU ". in Unix machine use grep in place of find
autorep -M agent_name -d
autorep -M -d shows jobs that are in running on the specified node.
autorep -M machine1 -d
Machine Name Max Load Current Load Factor O/S Status
machine1 --- --- 1.00 Sys Agent Online
Current Jobs:
Job Name Machine Status Load Priority
CMD1 machine1 RUNNING 0 0
CMD2 machine1 RUNNING 0 0
autorep -I MachineName | Find "RU"

How to use a single grep command to search a pattern from different unix servers

For Example,
I have two servers namely A and B. I want to use a grep command in either A or B, which will search in both A and B servers and display the match.
You could use parallel ssh (pssh) for that.
See this command:
parallel-ssh -P -v -l root -A -H "192.168.1.1 192.168.1.2 192.168.1.3" "hostname"
Where hostname is the command to execute on each of the hosts. -P means print the output of the command, -l root means login with the user root, -A ask for the password and -H provides the list of hosts.
The output might look similar to this:
192.168.140.193: hostname1
192.168.140.194: hostname2
192.168.140.195: hostname3
[1] 11:18:17 [SUCCESS] 192.168.140.193
[2] 11:18:17 [SUCCESS] 192.168.140.194
[3] 11:18:17 [SUCCESS] 192.168.140.195
For those without access to parallel-ssh, try this:
#!/bin/bash
remotehost='hostnameA'
if [ `hostname` == 'hostnameA' ]
then
remotehost='hostnameB'
fi
{
grep whatever
ssh $remotehost grep whatever
}
The first part figures out what host you're on and which it needs to ssh into. The second part performs the command on both hosts and groups the output together.

Login to multiple hosts and executing command in Unix

i want to write script where it will login into 50 hosts and if login is successful it print message "login to host1 is
successful" if not it should print message "Not able to login to host1". once connection to the host is succesful it should fire df command to check filesystem if df is stuck somewhere
then it should print message "DF got stuck otherwise print message "DF is successful"
Please advice how should i achive this
i used below approach
#!/usr/bin/ksh
for i in `cat host.txt`
do
ssh $i
if [[ $? -eq 0 ]] then
df
if [[ $? -eq 0 ]] then
return 0
else
echo "Something is wrong"
fi
else
echo "not able to do df"
fi
done
Thanks
You could do this in you script:
$ ssh loessl.org df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/xvda2 103212320 52448972 45520468 54% /
[..]
and/or have a look at pconsole
There are a million solutions to this, all of them too large to fit into this tiny box. Which one is right for you depends on your tastes (I prefer Dancer's Shell for small groups of machines and simple tasks, but other tools for larger tasks on more machines)
https://puppetlabs.com/mcollective/introduction/
http://rundeck.org/
http://docs.fabfile.org/en/1.0.1/index.html
http://func.et.redhat.com/
http://docs.opscode.com/knife.html
http://sourceforge.net/projects/dsh/
http://www.netfort.gr.jp/~dancer/software/dsh.html.en
http://sourceforge.net/apps/mediawiki/clusterssh/index.php?title=Main_Page
http://cssh.sourceforge.net/
But this is not something you're going to be solve with a few lines of bash.

Asterisk service and error logging

How can I log Asterisk service (service status, e.g. service is running or stopped) and Asterisk errors in a remote database?
so, with the /etc/asterisk.logger.conf you can have errors go to a syslog, which you can parse for errors and put into a DB. To check the status I recommend a bash script that looks for asterisk running and sends that status to mysql (if last column ordered by datetime) is different then the current status insert it into the db. You can use cron to check status every few minutes.
#!/bin/bash
APP=`ps -aux | grep -v 'grep' | grep 'asterisk'`
# 1 is false in BASH
APP_RUNNING=1
if [ $APP != "" ];
then
APP_RUNNING=0
fi

Resources