Unzip all files in a directory through SSH
Hello,
I am trying to unzip all tar.gz files in my current directory, so I use the following command: Code:
for f in *.gz ; do gunzip -c "$f" > ./"${f%.*}" ; done I read this can be done with the nohup command, so I tried the following: Code:
nohup for f in *.gz ; do gunzip -c "$f" > ./"${f%.*}" ; done & -bash: syntax error near unexpected token `do' So, then I tried the following: Code:
nohup sh -c "for f in *.gz ; do gunzip -c "$f" > ./"${f%.*}" ; done" & My question is: How can I write a job that unzips all files in a directory even if my session through ssh times out? Thank you. |
why do you lose connection?
maybe ssh has an option to carry on doing what it does on the remote machine, regardless of the connection? https://www.startpage.com/do/dsearch...onnection+lost - ok, it looks like nohup is what you need. maybe the command fails for other reasons, have you considered that? |
Remember that the quotes are there inside other quotes of the same kind. If you want them passed through to the remote machine while they are inside of other quotes, they must be escaped:
Code:
nohup sh -c "for f in *.gz ; do gunzip -c \"$f\" > ./\"${f%.*}\" ; done" & Code:
nohup sh -c 'for f in *.gz ; do gunzip -c "$f" > ./"${f%.*}" ; done' & Code:
while true; do |
nohup works on the first command, which is the for .... ; do is the second one. That's why it cannot work.
I would try: 1. create a script and run only that script on that remote host with nohup. 2. try remote execution by: echo "script" | ssh user@host /bin/bash |
Put the command in a script on the remote machine, then nohup the script
|
On the remote machine install screen. Screen lets you open terminal process which keeps running after logout or SSH disconnect.
Most important commands: Code:
screen -S myzip #create the screen process Reconnect with SSH Code:
screen -ls #find the name of your screen back jlinkels |
All times are GMT -5. The time now is 06:31 AM. |