We have two servers, one is aix and other is linux, so from our linux server, i am trying to invoked script that is located on aix to minimise script execution time. code: On linux machine
ssh user@$ip "sudo -u user2 'bash -c . /path (loading user profile) ; sh script.sh' "
On Aix machine:
script.sh
#/bin/bash
. /path [loading user profile]
db2 connect to db_name
db2 list tablespaces | grep -i state | wc -l > state_log
db2 list tablespaces | grep -i state | wc -l > normal_log
var1=$(cat state_log)
var2=$(cat normal_log)
if [[ "${var1}" == "${var2}" ]]
then
echo " tablespaces are normal "
else
echo "tablespaces are not normal"
fi
script is working fine on aix machine, however I am getting a error on linux machine
cat: cannot open state log and normal log : permission denied( even after giving
Full permission to file)
----++++New changes++++++
As per your advise in comment section, i have done some changes.
Now on linux machine below code i am using for invoking script on remote server.
ssh user@$ip 'sudo -u user2 bash script.sh'
On Aix machine:
script.sh
:
#/bin/bash
. /path [user profile]
if [[ `db2 connect to db_name | db2 list tablespaces | grep -i state | wc -l` == `db2 connect to db_name` | db2 list tablespaces | grep -i state | wc -l` ]]
then
echo " tablespaces are normal "
else
echo "tablespaces are not normal"
fi
script is now, not working fine on aix machine, Sometime it fetches value of first command in if loop and sometime second. I am not getting what's wrong with the code. Thanks in advance for all of your help !!!
+++++++New changes 2 +++++++
I have done following changes in aix script and it works for me.
#/bin/bash . /path [loading user profile]
db2 connect to db_name
db2 list tablespaces | grep -i state | wc -l > full_path_of_file1
db2 list tablespaces | grep -i state | wc -l > full_path_of_file2
var1=$(cat full_path_of_file1)
var2=$(cat full_path_of_file2)
if [[ "${var1}" == "${var2}" ]] then echo " tablespaces are normal " else echo "tablespaces are not normal" fi
Kind of weird behaviour of AIX OS but it works.
bash script.sh db_name
? The defaultsh
shell might be pointing to an older shell that cannot understand bash syntax.sh script.sh
(the arguments are not relevant). That executes the script using thesh
shell, but you have written your script using thebash
shell. Most modern Linux distros havesh
to be the same asbash
, but I believe AIX comes with a very old version ofksh
as the default shell. So, specifyingbash script.sh
in your SSH command line could resolve the issue.cat
at the end seems to refer to a file called (literally)state log and normal log
.cat
in the script.