Reputation: 167
I have a job like this:
The problem is, I have to add every server to my job configuration.
So is it possible to execute shell with parameterized remote ip like this?
#!/bin/sh
scp ${APP_NAME}.jar root@${REMOTE_IP}:/root/${APP_NAME}.jar
ssh root@${REMOTE_IP}
cd /root
ps -ef | grep ${APP_NAME} | grep -v grep | awk '{print $2}' | xargs kill
nohup java -jar ${APP_NAME}.jar &
Upvotes: 0
Views: 99
Reputation: 167
I solved this in another way.
#!/bin/sh
scp ${APP_NAME}.jar root@${REMOTE_IP}:/root/${APP_NAME}.jar
ssh root@${REMOTE_IP} "sh -s" -- < /opt/jenkins/my.sh ${REMOTE_IP} ${APP_NAME}
So my.sh is a local shell file which define how to start jar as server with parameterized ip
Upvotes: 1
Reputation: 3018
Yes. Use "$REMOTE_IP" to resolve it to the parameter value.
#!/bin/sh
scp ${APP_NAME}.jar root@"$REMOTE_IP":/root/${APP_NAME}.jar
ssh root@"$REMOTE_IP"
cd /root
ps -ef | grep ${APP_NAME} | grep -v grep | awk '{print $2}' | xargs kill
nohup java -jar ${APP_NAME}.jar &
Upvotes: 1