I need to get a value from a log file which I am getting using awk at the moment. I can get the number printing on the console but when I try to put that value into a new file nothing happens. Here is what i have
sshpass -p $PASSWORD ssh $USERNAME@$REMOTE_IP_ADDR tail -F $INPUT_FILE | awk '{ print $16 }' > $OUTPUT_FILE
//when command is run without > $OUTPUT_FILE i get my value eg 4000
This isnt a buffering issue because there is nothing being outputted to the file. A file gets created but the value isnt written to the new file. Also my value is always being overwritten as it is reading a line from another script which continuously replaces the line I read.
So i have fixed the problem I was having. The solution was assigning the command to a variable and the writing that variable to a file. I tried this before but the issue I had was i had an extra space between my = sign and the command. Here is the working code
value=`sshpass -p $PASSWORD ssh $USERNAME@$REMOTE_IP_ADDR tail -n 1 $INPUT_FILE | awk '{ print $16 }'`
echo $value
echo $value > $OUTPUT_FILE
//will not work because of the space between "value= `sshpass"
// value= `sshpass -p $PASSWORD ssh $USERNAME@$REMOTE_IP_ADDR tail -n 1 $INPUT_FILE | awk '{ print $16 }'`