Skip to content

Instantly share code, notes, and snippets.

@klang
Last active January 12, 2017 05:58
Show Gist options
  • Select an option

  • Save klang/e5364f0f5dcd17c0fb461f41940538c6 to your computer and use it in GitHub Desktop.

Select an option

Save klang/e5364f0f5dcd17c0fb461f41940538c6 to your computer and use it in GitHub Desktop.
user is logged in on a ssh connection and has to call a rest service running on his local machine
#!/bin/bash
foo=$(pstree -c -p -s $$ | awk -Fsshd '{print $3}' | cut -f2 -d '(' | tr -d ')' | tr -d '-')
caller=$(who -u | grep $foo | cut -f2 -d '(' | tr -d ')')
# a few other ways to get the IP
TTy=$(ps -eo pid,tty|grep $$|awk '{print $2}')
WhoAmI=$(who -u |grep -e "$TTy")
TheIp=$(echo $WhoAmI | awk '{print $7}' | sed 's/[()]//g'
read INPUT
curl --header "Content-type: application/json" --request POST --data $INPUT http://$caller/rest/service
# user is logged in on a ssh connection and has to call a rest service running on his local machine
# cat json-data.json | call-rest-service-on-caller-machine.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment