I need to run a ssh script on a remote linux server to add a user but nothing I do quite works.
I make up the username of 2 Parameters and then try to make the password of which the first part is a set string but the second part is also a Parameter. I am using the Jenkins SSH Plugin to run scripts over ssh. The first part, useradd works because I disabled sudo password for the admin user. But the passwd doesnt want to work…
I am currently trying:
sudo useradd $FIRSTPART1_$SECONDPART2 echo -e 'PASSWORD_$SECONDPART2nPASSWORD$SECONDPART2n' | sudo passwd $FIRSTPART1_$SECONDPART2
I suspect the problem is the double-paramaters after each other.
any ideas?
Advertisement
Answer
Try to use double quotes instead of single for the echo command.
Further, without using the ssh plug-in, you can have it simple and execute a bash script locally on the build machine (e.g. in the custom build step where you can provide / write a script), provided you have ssh login without password (e.g. via key) enabled such that jenkins user can login to the target:
# Login ssh user@remote << ENDSSH # use normal commands as you would on shell or a local script; # any variables set previously in this bash script remain valid though sudo useradd $FIRSTPART1_$SECONDPART2 echo -e "PASSWORD_$SECONDPART2nPASSWORD$SECONDPART2n" | sudo passwd $FIRSTPART1_$SECONDPART2 ENDSSH