Have you been in a situation that you wanted to know how to
watch
There are some situations where running a command only once is not enough, and you might have to run it in a continuous fashion. This sometimes happen when you have to track the status of a process and there is not an async way of checking and only a polling method is available, such as a status endpoint.
In those cases, you may want to use the command watch
that will execute the command that you pass as a parameter every n seconds.
watch -n 1 'curl -s localhost:27182/api/v1/progress -X GET | jq .'
Bonus tip:
If the return of the command you are executing has a JSON format, you can execute jq
command to parse it so it can be parsed on every execution. Watch out, because if you don't add the .
after jq, the command will not work properly.
scp
If you want to copy a file from your VM (in this case an EC2 instance in AWS) to your local instance using scp (copy through ssh):
scp -i "david-sanchez-key.pem" ec2-user@ec2-1-10-15-121.eu-west-1.compute.amazonaws.com:/home/ec2-user/logs.log /Users/user/Downloads
You have to replace the following:
- Path to the key
- VM username
- VM hostname
- VM path to file to copy
- Local destination path
And if you want to copy from your local to your VM:
scp -i "david-sanchez-key.pem" /Users/folder1/logs.log ec2-user@ec2-1-10-15-121.eu-west-1.compute.amazonaws.com:/home/ec2-user