My goal is to ssh into several host, check when the current branch was modified, and if older than 48 hours, mark the host as available. Eventually, I'll need to schedule this as a cron job but I haven't gotten to that level yet.
I have this:
hosts="rick morty beth jerry summer"
extra_vars="release_branch=$1"
show_deployed_branches() {
for host in $hosts
do
if [[ ! -z "$branch_dir" ]]; then
branchstamp=`$SHELL_AS ssh -o StrictHostKeyChecking=no $host cat $branch_dir/* 2> /dev/null`
printf " [*] %s:\n%s\n" $host "$branchstamp"
else
branchstamp=`$SHELL_AS ssh -o StrictHostKeyChecking=no $host cat $branch_file 2> /dev/null`
printf " [*] %s: %s\n" $host "$branchstamp"
fi
done
}
This will show the following:
[*] rick: GLIB-1111 on February 28 at 08:30 UTC by Birdman
[*] morty: BLEM-2371 on February 26 at 16:55 UTC by Birdman
[*] beth: AVAILABLE
[*] jerry: DOPE-12 on March 01 at 19:28 UTC by Birdman
[*] summer: MAIN on March 01 at 18:17 UTC by MrPoopyButthole
If I want to make Jerry available, I run the following:
release_box(jerry) {
$SHELL_AS ssh -o StrictHostKeyChecking=no $1 "echo 'AVAILABLE' > $branch_file" 2> /dev/null
echo " [*] Finished with $1"
I know this requires an if statement, but I'm stumped on next steps. I know an If statement is needed but don't know what will read the modified date and determine that its too old.
Related
Has anyone installed/run ActiveMQ on IBM i and can help me with this?
Either the process does not run or gives ZipException.
I downloaded ActiveMQ 5.16.2 from ActiveMQ 5.16.2 (Apr 28, 2021) - Unix/Linux/Cygwin bundle
for installing on IBMi V7R3 and followed the official steps for installation mentioned on Version 5 Getting Started - 'Installation Procedure for Unix' section.
This is similar to installing on IBMi as mentioned in - Installing activeMQ on IBM i5 V5R4
On running the command ./bin/activemq start, the process starts but ends without actually running ActiveMq.
It shows below error on the console -
./bin/activemq: 001-0019 Error found searching for command whoami. No such path or directory.
Also the command ./bin/activemq status returns ActiveMQ not running .
When running the command ./bin/activemq console, the process starts but gives the same whoami error and ends with ZipException.
On Windows, I have been able to install and run successfully.
Has anyone installed ActiveMQ on IBMi and can help me with this?
You are missing the command
whoami
This is not a shell built-in, so you would need to add that package to your installation.
h/t to #nfgl for the pointer to the IBM OSS rpm repo. If you inspect their src.rpm, you'll see they patch the activemq script. Worth reviewing
SRC RPM calls for this dependency: coreutils-gnu
IBM iSeries Patch of bin/activemq:
$ more activemq-activemq.patch
--- a/bin/activemq 2020-03-30 18:50:50.000000000 +0000
+++ b/bin/activemq 2020-03-30 18:57:03.000000000 +0000
## -336,10 +336,14 ##
-Dactivemq.data=\"${ACTIVEMQ_DATA}\" \
$ACTIVEMQ_CYGWIN \
-jar \"${ACTIVEMQ_HOME}/bin/activemq.jar\" $COMMANDLINE_ARGS >> $ACTIVEMQ_OUT 2>&1 &
- RET=\"\$?\"; APID=\"\$!\";
- echo \$APID > "${PIDFILE}";
- echo \"INFO: pidfile created : '${PIDFILE}' (pid '\$APID')\";exit \$RET" $DOIT_POSTFIX
- RET="$?"
+ exit \"\$?\"" $DOIT_POSTFIX
+ RET="$?"
+ sleep 5
+ OS400_PID=`ps | grep -iE 'java|jFromPASE|jvmStartPase|qp0zspwp' | grep -v '\spgm-' | grep -vE '^\s+1\s' | tail -n 1 | awk '{print $1}'`
+ rm -f $PIDFILE
+ qsh -c "/usr/bin/touch -C 1208 $PIDFILE"
+ echo $OS400_PID > $PIDFILE
+ echo "INFO: pidfile created : '$PIDFILE' (pid '$OS400_PID')"
elif [ -n "$TASK_TODO" ] && [ "$TASK_TODO" = "stop" ];then
SPID="`cat "${PIDFILE}"`"
$EXEC_OPTION $DOIT_PREFIX "\"$JAVACMD\" $ACTIVEMQ_OPTS $ACTIVEMQ_DEBUG_OPTS \
## -384,7 +388,7 ##
return 2
fi
ACTIVEMQ_PID="`cat ${ACTIVEMQ_PIDFILE}`"
- RET="`ps -p "${ACTIVEMQ_PID}"|grep java`"
+ RET=`/QOpenSys/usr/bin/ps -p ${ACTIVEMQ_PID}|grep -iE 'java|jFromPASE|jvmStartPase'`
if [ -n "$RET" ];then
return 0;
else
## -403,7 +407,7 ##
return 2
fi
THEPID=`cat ${PID_STOP}`
- RET=`ps -p $THEPID|grep java`
+ RET=`/QOpenSys/usr/bin/ps -p ${ACTIVEMQ_PID}|grep -iE 'java|jFromPASE|jvmStartPase'`
if [ -n "$RET" ];then
return 0;
else
There are two scripts on HostB
# loop.sh
while true; do
date
sleep 2
done
and
# loop12.sh
optv=$1
while true; do
case $optv in
2)
echo "from stderr" >&2
date >&2
;;
*)
echo "from stdout"
date
;;
esac
sleep 2
done
I run ssh HostB './loop.sh &' on HostA, the Terminal prints the date every 2 seconds.
When I press Ctrl + c to stopssh HostB running on HostA, and check the process with ps -ef | grep loop on HostB, the process loop.sh is still there.
I run ssh HostB './loop12.sh &' on HostA, the Terminal prints the date every 2 seconds, too.
But when I press Ctrl + c to stopssh HostB running on HostA, and check the process with ps -ef | grep loop12 on HostB, the process loop12.sh is gone.
I just wonder Why the scripts are similar but they have different phenomenon?
backup.sh has :
#!/bin/bash
expect backup.exp
tr -d '\15\32' < backup.templog > backup.log
backup.exp has next content:
#!/usr/bin/expect -f
puts "----------------- [exec date +%Y.%m.%d\ %H:%M:%S] ------ exp start -----\n"
spawn ssh root#someIP2
expect "# "
send "su - postgres\r"
expect "\$ "
send "ls -lh db.dump.gz\r"
send exit\r
send exit\r
interact
when I run manually like next:
bash backup.sh >> backup.templog 2>&1
I get next, which I like:
spawn ssh root#someIP
Linux db01 3.2.0-4-amd64 #1 SMP Debian 3.2.68-1+deb7u1 x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Sep 2 11:06:02 2015 from someIP2
root#db01:~# su - postgres
postgres#db01:~$ ls -lh /var/lib/postgresql/db.dump.gz
-rw-r--r-- 1 postgres postgres 218M Sep 2 10:39 /var/lib/postgresql/db.dump.gz
postgres#db01:~$ exit
logout
root#db01:~# exit
logout
Connection to someIP2 closed.
but with cron (has a line):
* * * * * bash backup.sh >> backup.templog 2>&1
I get only next:
spawn ssh root#someIP2
Linux db01 3.2.0-4-amd64 #1 SMP Debian 3.2.68-1+deb7u1 x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Sep 2 11:04:13 2015 from someIP1
root#db01:~# su - postgres
postgres#db01:~$
Can I get the same with cron and manually?
I have a string as below, I needed to exactly match if string "abc.properties abc Scanner directory: /xyz/xzy/" is present.
I am using the below awk command.
It considers as successful if even a part of string, say, abc.properties is present. But, my criteria is to check for the exact string i.e. "abc.properties abc Scanner directory: /xyz/xzy/".
Can somebody please help?
echo $s | awk 'BEGIN { FS="\n"; RS="";} /abc.properties abc Scanner directory: \/xyz/xzy\// {print $1}'
String is as below:
spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -o ServerAliveInterval=600 -o ServerAliveCountMax=3 -o ConnectTimeout=30 xyz#123.abc.com Password: Creating directory '/home/xyz'. Authorized uses only. All activity may be monitored and reported. Successful login using -u option. If you want to allow X traffic please use -x option. Usage: /111/11/111/111 [policy] -x [target user] su from xyz to abc [abc#xyz ~]$ /111/111/111/111/111/111.sh /111/11/instance/111/111/111/111/ Verifying JVM setting for domain: /111/11/11/11/1111/111/111// abc.properties abc Scanner directory: /xyz/xzy/ [abc#xyz ~]$ exit 0 logout
The output is as below:
$ echo $s | awk 'BEGIN { FS="\n"; RS="";} /abc.properties abc Scanner directory: \/xyz/xzy\// {print $1}'
spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -o ServerAliveInterval=600 -o ServerAliveCountMax=3 -o ConnectTimeout=30 xyz#123.abc.com Password: Creating directory '/home/xyz'. Authorized uses only. All activity may be monitored and reported. Successful login using -u option. If you want to allow X traffic please use -x option. Usage: /111/11/111/111 [policy] -x [target user] su from xyz to abc [abc#xyz ~]$ /111/111/111/111/111/111.sh /111/11/instance/111/111/111/111/ Verifying JVM setting for domain: /111/11/11/11/1111/111/111// abc.properties abc Scanner directory: /xyz/xzy/ [abc#xyz ~]$ exit 0 logout
On HostA, I have a process, procA, that does I/O, like so:
#!/bin/bash
while sleep 1 ; do
# Consume input *if available*
if read -t 0.5 x; then # a timed-read
# If input is available, output it.
echo "HostA Input: $x"
fi
# Produce some output.
echo "HostA Output: $(date)"
done
On HostB, I have a very similar process, procB, with the only difference that procB tags its input/output with the prefix HostB (instead of the prefix HostA).
Now, I want to use the netcat program (/usr/bin/nc) to send procA's stdout to procB's stdin, and procB's stdout to procA's stdin. My expectation in all this is that HostA's output should appear on HostB, and HostB's output should appear on HostA... much as would happen in following canonical nc example of a peer-to-peer chat:
[HostB]$ nc -l 4000
[HostA]$ nc HostB 4000
But, when I tried to extend the above canonical example by replacing the human at both hosts with processes procA and procB as follows, it did not work:
On HostB:
$ mkfifo p
$ ./procB <p | nc -l 4000 >p
<WHY NO OUTPUT HERE??>
and, on HostA:
$ mkfifo p
$ ./procA <p | nc HostB 4000 >p
<WHY NO OUTPUT HERE??>
Notes:
I have verified that port 4000 is open on HostB.
Unidirectional communication, such as the following, seems to work:
On HostB:
$ mkfifo p
$ ./procB <p | nc -l 4000 >p
On HostA:
$ ./procA | nc HostB 4000
HostB Output: Wed Jan 11 13:53:37 IST 2012
HostB Output: Wed Jan 11 13:53:39 IST 2012
HostB Input: HostA Output: Wed Jan 11 13:55:02 IST 2012
HostB Output: Wed Jan 11 13:53:40 IST 2012
HostB Input: HostA Output: Wed Jan 11 13:55:04 IST 2012
HostB Output: Wed Jan 11 13:53:41 IST 2012
HostB Input: HostA Output: Wed Jan 11 13:55:05 IST 2012
HostB Output: Wed Jan 11 13:53:42 IST 2012
^C
Now, I know that nc comes with an INSECURE option -e that could somehow be employed if it's enabled in your nc binary, but assuming that I don't have -e option available, how can I connect 2 remote processes to each other via nc? Basically, where I'm going wrong above? Why there is no output in the places I have indicated above? Many thanks in advance.
The behavior described above is actually the right behavior, just that I did not realize that it was.
Wherever I was complaining about <WHY NO OUTPUT HERE??>, it was/is because the stdout's of the terminals have been redirected to the local fifos. (No wonder, you don't see anything on the terminal!)
Further, in Notes (2) above, it is not really true that the communication is unidirectional; it is very much bidirectional, just that you don't get to see any output on HostB, once again, because stdin and stdout have redirected from the terminal to the fifo. Thus, you correctly see procB's output on HostA, which is nothing but the output of procA on HostA sent to procB on HostB as procB's input!
Wow!
EDIT:
To actually see the output on each terminal, use tee, like so:
On HostB:
$ mkfifo p
$ ./procB <p | nc -l 4000 | tee p
On HostA:
$ mkfifo p
$ ./procA <p | nc HostB 4000 | tee p