I am passing a small series of commands to a remote server through ssh. the basic format is:
sshpass -p $password ssh $username@$host -p $port $commands
the commands are passed in the form of a string, like this:
commands="command1; command2; etc..."
this has worked smoothly in previous applications. however, for this one, the first thing i need to do is create a temp directory with mktemp -d
and cd into it. i need a oneliner to do this because i wont have “interactive” access in order to manually input commands (this is meant for an automated task).
the issue i’m having is this: either the temp directory is created but CWD doesn’t change, or it isn’t created at all.
any help would be much appreciated. thanks in advance.
i have tried the following:
commands="cd $(mktemp -d)"
>> returns “no such file or directory”
commands="TEMP=$(mktemp -d); cd $TEMP"
>> looks like $TEMP isn’t created for some reason
commands="cd /tmp; cd $(cat $(mktemp -d > dir.txt))"
>> returned nothing
plasticglass is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.