I am currently using,
curl -u ${username}:${password} --output /dev/null ${url}
I believe by this approach password will be visible in ps tree. Is there any approach I can use by avoiding this?
The contents of -u are not visible via ps, but remember your History file.
Generally you should avoid Passwords in parameters!
If you downvote.. better tell why:
running a curl -u user:password nopaste.info/login
`--> ps aux | grep curl
t4c 30540 0.0 0.0 103516 2668 pts/5 S+ 13:12 0:00 curl -u nopaste.info/login
As you can see there is no -u output attached.
Related
This may look a silly simple question, but I can't find the appropriate method to find the caller.
I have a tool that can be used from different applications. I want to record who is using it.
Note that when sourcing, using source (or the dot shortcut), the executing program is bash (or your designated shell). In this case, only if you source 'tool', the calling history will be preserved on ${BASH_SOURCE[*]}, including the calling line on ${BASH_LINENO[*]}.
I expect BASH_SOURCE give some hint (history), however, the tool is not sourced so, there is no references to caller on 'BASH_SOURCE'.
#!/bin/bash
# this is the tool: I'm expecting to have 'client' somewhere
echo "Source ${BASH_SOURCE[*]}"
ps -axj | grep "\s$$\s"
echo "tool: ${*}"
now, this is the client caller
#!/bin/bash
# this is the client
chmod +x ./tool # I'm making this explicit
./tool this is a test
This is the result:
$ . ./client
Source ./tool
30389 17217 17217 30389 pts/1 17217 S+ 0 0:00 /bin/bash ./tool this is a test
17217 17218 17217 30389 pts/1 17217 R+ 0 0:00 ps -axj
17217 17219 17217 30389 pts/1 17217 S+ 0 0:00 grep \s17217\s
30380 30389 30389 30389 pts/1 17217 Ss 0 0:01 -bash
tool: this is a test
This might help with Linux:
#!/bin/bash
GPPID=$(ps -o ppid= -p $PPID | tr -d ' ')
cat /proc/$GPPID/comm
Would adding ps -o comm= -p $PPID to tool do what you're after?
Edit:
Adding sample output
tink#box ~/tmp$ ./client
Source ./tool
15576 15578 15576 9978 pts/3 15576 S+ 1000 0:00 /bin/bash ./tool this is a test
tool: this is a test
client
I seem to have a weird issue:
I want to restart a reverse ssh tunnel on boot, I've tried it with an init script (that works fine when executed as user) and with an added line in /etc/rc.d but none of it works. What I get after boot is:
$ ps ax | grep autossh
397 pts/10 S+ 0:00 grep --color=auto autossh
1351 ? Ss 0:00 /usr/lib/autossh/autossh -M 22221 -N -o PubkeyAuthentication=yes -o PasswordAuthentication=no -i ~/.ssh/etherwan.key -R 19999:localhost:22 ubuntu#server
but I'm unable to login from server. So I did the following after boot:
$ sudo killall -KILL autossh
[sudo] password for ron:
$ /usr/bin/autossh -M 22221 -f -N -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i ~/.ssh/etherwan.key -R 19999:localhost:22 ubuntu#server
upon which I can login using port 19999 just fine!
The keys permissions look like: (but root should not need to care, would it?)
$ ls -l ~/.ssh/etherwan.key
-r-------- 1 ron ron 1675 Nov 6 04:15 /home/ron/.ssh/etherwan.key
Replace ~/.ssh/etherwan.key in your rc.d script with /home/ron/.ssh/etherwan.key
The '~' character is expanded to the user's home directory by the shell, but rc.d scripts are run as root.
I have followed instructions from
https://www.digitalocean.com/community/tutorials/how-to-use-ssh-keys-with-digitalocean-droplets
But my terminal looks like
ps auxw | grep ssh
milenko 21891 0.0 0.0 21292 924 pts/4 S+ 16:24 0:00 grep --color=auto ssh
Should I kill 21891?
What does grep --color auto stand for?Can someone elaborate more om this?
grep --color=auto is the grep from the line above. When you would try to kill it later, it will no longer be there, because the above command ended.
The reason why the line does not list only grep ssh is, that you have alias for grep to be nicely colored:
$ which grep
alias grep='grep --color=auto'
/usr/bin/grep
TLDR what is going on there: Your sshd server is not running.
I'm running ubuntu 14.04 and I just want to restart (stop and start) couchDB, which is running on cloud 9. I tried these but none of them seems to work:
1.
ps -U couchdb -o pid= | xargs kill -9
2.
sudo couchdb stop
3.
curl -X POST http://[username]:[password]#127.0.0.1:5984/_restart -H"Content-Type: application/json"
Starting the couchdb the way the Cloud9 doc says will allow a simple Control + C to close it:
sudo mkdir -p /var/run/couchdb
sudo chown couchdb:couchdb /var/run/couchdb
sudo su couchdb -c /usr/bin/couchdb
However is that's not what you want you can always find the PID and kill it:
mikeumus#couchdb:~/workspace (master) $ pstree -ap|grep couchdb
| |-grep,9050 --color=auto couchdb
`-sudo,9018 su couchdb -c /usr/bin/couchdb
`-su,9019 couchdb -c /usr/bin/couchdb
`-beam.smp,9020 -Bd -K true -A 4 -- -root /usr/lib/erlang -progname erl -- -home /var/lib/couchdb ---noshe
mikeumus#couchdb:~/workspace (master) $ sudo kill -- -9018
mikeumus#couchdb:~/workspace (master) $ pstree -ap|grep couchdb
| |-grep,9071 --color=auto couchdb
Don't mind the color process still running, the couchdb process is now off. If you want to find and kill the couchdb in a single command, try:
kill $(ps aux | grep '[c]ouchdb' | awk '{print $2}')
Explained in this Stack Overflow Answer: https://stackoverflow.com/a/3510850/1762493
If there a way to log multiple TxStatus codes with varnishlog ?
Varnishlog man states that there not :)
How could I log multiple codes ?
My command now looks like varnishlog -c -m TxStatus:301
Thank you in advance!
You can try this syntax:
{ varnishlog -c -m TxStatus:301 & varnishlog -c -m TxStatus:404 & } > varnish-status.log
To view live logs:
tail -f varnish-status.log
To stop logging:
$ ps ax | grep varnishlog
5009 pts/0 S 0:00 varnishlog -c -m TxStatus:301
5010 pts/0 S 0:00 varnishlog -c -m TxStatus:404
5636 pts/0 S+ 0:00 grep varnishlog
$ kill 5009
$ kill 5010