I`ve created a .bat file to open the connection on Putty:
putty.exe -ssh IP -l "user" -pw "password" -m C:\my\Test\dir\commands.txt -t
And then I run some commands
echo "password" | sudo -S ; ls ; "etcetera etcetera" ; script.sh ; sleep 10s
But when I run the script 'script.sh' it tells me: 'Command not found'.
If I run the commands manually instead, it works perfectly. I think there is some problem in running the script remotely, is there any way to solve the problem?
EDIT
I modified the .bat file like this:
plink.exe -ssh IP -l "user" -pw "password" -m C:\my\Test\dir\commands.txt -t
and the command file in this way:
(
echo "password" | sudo -S
ls
script.sh
)
but it still says "command not found".
I have also tried "/usr/local/bin/script.sh" ma it says "permission denied", so maybe it is related to that? But in case it is why "manually" I can run it in both ways?
RE-EDIT
Something was wrong with the first commands, so the password was not taken into account. However, the command.txt file now looks like this:
(
sudo -S <<< "password" ls
sudo -i
cd /tmp
chmod +x file
./file
script.sh
)
But unfortunately it seems that after the password has been taken another command cannot be taken.
So the output is now as follows:
plink.exe -ssh IP -l "user" -pw "password" -m C:\my\Test\dir\commands.txt -t Access granted. Press Return to begin session. Password: root:~# and don`t continue.
SOLVED
I modified the command.txt like this:
(
sudo -S <<< "password" ls
sudo -i -- bash -c 'cd /tmp && chmod +x file && ./file && script.sh '
)
and it works