Skip to content

Instantly share code, notes, and snippets.

@joelhoro
Created June 28, 2020 19:27
Show Gist options
  • Save joelhoro/bf244e13cb561a4a7ef26417f3aeb102 to your computer and use it in GitHub Desktop.
Save joelhoro/bf244e13cb561a4a7ef26417f3aeb102 to your computer and use it in GitHub Desktop.
Run file and redirect output to logfile w pid in its name
#!/bin/bash
basedir="/home/joel/processes/log"
export PYTHONUNBUFFERED=1
logfile=$(date +%H%M%S.%N)
oldname="$basedir/log-$logfile.log.tmp"
#echo "Old name: $oldname"&
echo "$2" > $oldname
echo $(pwd) >> $oldname
$2 &>> $oldname &
newname="$basedir/$1-$(date +%H%M%S)-PID=$!.log"
echo "Logging '$1' \"$2\" to $newname"
mv $oldname $newname
#less +F $newname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment