1

Below is my code and I am able to get the ssh connection. But after that it is doing nothing.

log_time="date +%F\%T"
PR_ONE="username@hostname"
file="/home/log.txt"
to_list="myemail"
echo "`$log_time`" >> $file
`ssh $PR_ONE "echo df -hP | grep fs1 | awk '{print $4}'"` >> $file
cat $file | mailx -s "Disk space usages" $to_list

I am getting the email but only with $log_time. I know that I am doing something wrong in quotations in the ssh line.

I am new to shell scripting.

James Z
  • 12,209
  • 10
  • 24
  • 44
zeewagon
  • 1,835
  • 4
  • 18
  • 22

1 Answers1

2

Try this :

echo "df -hP | grep fs1 | awk '{print $4}'" | ssh -tt $PR_ONE >> $file

or prefer this :

ssh -tt $PR_ONE << EOF >> $file
df -hP | grep fs1 | awk '{print $4}'
EOF
Indent
  • 4,675
  • 1
  • 19
  • 35
  • The first command worked. But I got a warning message as `Pseudo-terminal will not be allocated because stdin is not a terminal.` during the execution. Also what I am getting is `/dev/mapper/VolGroup01-fs2vol 7.4T 6.4T 593G 92% /net/si-091l/fs1`, but I want is `$4` of `awk` which is `593G` alone. – zeewagon Dec 11 '17 at 10:31
  • use `ssh -tt` to force pseudo-tty allocation – Indent Dec 11 '17 at 10:40