Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

Friday, October 2, 2015

Execution of command right after process is finished in bash

Task : you have one java process running and it run for long time and you need to execute smth right after it is finished.

First of all, get details of running job:

[user@myserver ~]$ jps -vm
32632 Jps -vm -Dapplication.home=/opt/jdk1.8.0_45 -Xms8m
16364 Shell --home /var/jenkins/jobs/validator --processor com.mycompany.Validator -Xmx1024m 

[user@myserver ~]$ jps -vm | grep Validator
16364 Shell --home /var/jenkins/jobs/validator --processor com.mycompany.Validator -Xmx1024m 

Now you want to get time when it was finished:
[user@myserver ~]$ 
while [[ `jps -vm | grep Validator | wc -l` != 0 ]]; do sleep 60; done; echo "finished at `date`"

Instead of "echo "finished at `date`"" you can put any other command, 60 seconds waiting was ok for my task.

Instead of "jps -vm" you can use "ps -ax" or whatever you like to grab process id or process details.
On SunOS "ps -Af".

FYI, to do smth and send email:
JOB="my-job" && while [[ $(jps -vm | grep $JOB | wc -l) != 0 ]]; do sleep 60; done; echo "echo smth valuable" ; echo "" | mailx -s "mailx: $JOB is finished and do_smth_valuable is done" myemail@mycompany.com,myemail2@mycompany.com

.

Wednesday, June 5, 2013

Bulk files rename in linux


Task: in folder /www/logs/jobs/ rename all files started from "rp-repgen" to "repgen", in other words change prefix of files.

Solution:
 for file in /www/logs/jobs/rp-repgen*; do dest="${file/rp-repgen/repgen}";mv $file $dest; done

Sunday, January 20, 2013

How to show git branch/status information in bash

extension for terminal/command line to use git more effectively:

For Mac users, (zsh): https://github.com/olivierverdier/zsh-git-prompt

For bash(works fine for Ubuntu): https://github.com/magicmonty/bash-git-prompt
I do following update for /home/USER/.bash/gitprompt.sh :
PROMPT_START="$WHITE$Time12a $Yellow$PathShort$ResetColor"
PROMPT_END=" $ "

For simple branch show(works very fast), (link second comment):
Simply add following line it ~/.bashrc
PS1='[\u@\h`__git_ps1` \W]\$ '



Wednesday, December 28, 2011

My favorite bach command prompt PS1

cd ~
nano .profile
add following line at the end
PS1="[\u@\h \W]$ "
export PS1

logout/login

easy to read link for more.