Im trying to automate the Establishment of symlinks depending on the memory usage of a machine, for this i want to first check what directory under my main directory is using the most Memory, for this i am using this command
cd /directory && du -h 2>/dev/null | awk '{ if ($1 ~ /G/) {print $0}}' | grep './' | awk -F '.' '{print $3}'
This works perfect over a ssh connection , but when i try to put it in a script under expect i get the error:
{ if ( ~ /G/) {print myscriptname}}
^ parse error
{ if ( ~ /G/) {print myscriptname}}
^ parse error
What i find most wierd about this is that somehow the command is trying to use my actual script´s file name as an argument even tough i am running the command trough a ssh connection.
My complete code is
#!/bin/bash
expect <<-EOF
set timeout 5
spawn ssh -oPort=22 user@ip
expect "*password" { send "password\r" }
expect "*#" { send "cd /directory && du -h 2>/dev/null | awk '{ if ($1 ~ /G/) {print $0}}' | grep './' | awk -F '.' '{print $3}'\r" }
expect "*#" { send "exit\r" }
EOF