nohup

is it possible to use variables in remote ssh command?

蹲街弑〆低调 提交于 2019-11-27 05:27:42
I'd like to execute several commands in sequence on a remote machine, and some of the later commands depend on earlier ones. In the simplest possible example I get this: ssh my_server "echo this is my_server; abc=2;" this is my_server abc=2: Command not found. ssh my_server "echo this is my_server; abc=2; echo abc is $abc" abc: undefined variable For a bit of background info, what I actually want to do is piece together a path and launch a java application: ssh my_server 'nohup sh -c "( ( echo this is my_server; jabref_exe=`which jabref`; jabref_dir=`dirname $jabref_exe`; java -jar $jabref_dir

Nohup is not writing log to output file

坚强是说给别人听的谎言 提交于 2019-11-27 05:03:18
问题 I am using the following command to run a python script in the background: nohup ./cmd.py > cmd.log & But it appears that nohup is not writing anything to the log file. cmd.log is created but is always empty. In the python script, I am using sys.stdout.write instead of print to print to standard output. Am I doing anything wrong? 回答1: It looks like you need to flush stdout periodically (e.g. sys.stdout.flush() ). In my testing Python doesn't automatically do this even with print until the

What's the nohup on Windows?

不问归期 提交于 2019-11-27 04:22:22
I want to run a Java jar file like this: java -jar spider.jar How to run it on the background on Windows? Like this on Linux: nohup java -jar spider.jar > /var/tmp/spider.log 2>&1 & On Windows it's not normal that a process terminates once its parent was killed (like Unix-likes do it normally). Therefore there is no direct necessity for something like nohup . If you want to avoid the console window associated with it, you can use javaw but redirection won't work, then. You could use the Windows start command: start /min java -jar spider.jar This command is not really the same as nohup ; but it

Linux Bash

白昼怎懂夜的黑 提交于 2019-11-26 23:05:15
SET 命令 用途: 可以设置 shell 的执行方式,不带参数时输出环境变量。 > set [+-abCdefhHklmnpPtuvx] 注: 1. [-] 表示设置参数 2. [+] 表示取消设置参数 示例: > tmp="nice day" > $tmp nice day > set | grep tmp tmp="nice day" > unset tmp > $tmp SSH 命令 用途: 连接远程计算机。 > ssh -p <port> <user>@<hostname> <remote cmd> 注: [-p] 指定端口号,默认为 22 [remote cmd] 远程执行命令并显示到本地继续工作 配置 [.ssh] 在 [~/.ssh/config] 中, Host <myhost> User <username> HostName <ip> IdentityFile ~/env/<username>.id_rsa 可快速进行ssh连接, ssh myhost 。 SSHPASS 命令 不用提示输入密码,直接使用配置的密码进行远程登录,适用于脚本。 安装: # Ubuntu apt-get install sshpass # Mac brew install https://raw.githubusercontent.com/kadwanev/bigboybrew

Linux中长时间运行程序的方法

无人久伴 提交于 2019-11-26 21:14:17
一、场景: 如果临时有一个命令需要长时间运行,比如 python hello.py ,什么方法能最简便的保证它在后台稳定运行呢? 解决方法: 当用户注销(logout)或者网络断开时,终端会收到 HUP(hangup)信号从而关闭其所有子进程。 因此,我们的解决办法就有两种途径:要么让进程忽略 HUP 信号,要么让进程运行在新的会话里从而成为不属于此终端的子进程。 二、nohup nohup 无疑是我们首先想到的办法。顾名思义,nohup 的用途就是让提交的命令忽略 hangup 信号。 只需在要处理的命令前加上 nohup 即可,标准输出和标准错误缺省会被重定向到 nohup.out 文件中。一般我们可在结尾加上"&"来将 命令同时放入后台运行 nohup python hello.py & 来源: https://www.cnblogs.com/zongfa/p/11333589.html

How to get the process ID to kill a nohup process?

社会主义新天地 提交于 2019-11-26 21:08:32
I'm running a nohup process on the server. When I try to kill it my putty console closes instead. this is how I try to find the process ID: ps -ef |grep nohup this is the command to kill kill -9 1787 787 lurker When using nohup and you put the task in the background, the background operator ( & ) will give you the PID at the command prompt. If your plan is to manually manage the process, you can save that PID and use it later to kill the process if needed, via kill PID or kill -9 PID (if you need to force kill). Alternatively, you can find the PID later on by ps -ef | grep "command name" and

How to include nohup inside a bash script?

时光总嘲笑我的痴心妄想 提交于 2019-11-26 20:59:54
问题 I have a large script called mandacalc which I want to always run with the nohup command. If I call it from the command line as: nohup mandacalc & everything runs swiftly. But, if I try to include nohup inside my command, so I don't need to type it everytime I execute it, I get an error message. So far I tried these options: nohup ( command1 .... commandn exit 0 ) and also: nohup bash -c " command1 .... commandn exit 0 " # and also with single quotes. So far I only get error messages

What&#39;s the difference between nohup and ampersand

我只是一个虾纸丫 提交于 2019-11-26 14:50:39
Both nohup myprocess.out & or myprocess.out & set myprocess.out to run in the background. After I shutdown the terminal, the process is still running. What's the difference between them? nemo nohup catches the hangup signal (see man 7 signal ) while the ampersand doesn't (except the shell is confgured that way or doesn't send SIGHUP at all). Normally, when running a command using & and exiting the shell afterwards, the shell will terminate the sub-command with the hangup signal ( kill -SIGHUP <pid> ). This can be prevented using nohup , as it catches the signal and ignores it so that it never

linux常用命令总结

帅比萌擦擦* 提交于 2019-11-26 14:29:27
0.最常用 (1)关机sudo shutdown -h now 立刻关机 或者指定时间关机 shutdown -h 22:22 (2)重启sudo reboot 1.用户管理 (1)新增用户:adduser比useradd好用。例如adduser uasername 其中username指代你想删除的用户名 (2)删除用户:userdel username或者彻底删除 userdel -r username 其中username指代你想删除的用户名 (3)新增用户组: groupadd –g 888 groupname 其中groupname指代组名,888指代组的GID 删除用户组: groupdel groupname 删除组groupname 为用户组添加用户 gpasswd –a username groupname 其中username指代用户名,groupname指代组名 为用户组删除用户gpasswd –d username groupname (4)为当前用户添加root权限(root用户执行) gedit /etc/sudoers,在其中添加 username ALL=NOPASSWD:ALL 然后保存 其中username代表你想赋予root权限的账号 (5)为当前 用户添加环境变量 第一步:gedit ~/.bashrc #打开环境变量文件 第二步:

Why can&#39;t I use Unix Nohup with Bash For-loop?

三世轮回 提交于 2019-11-26 13:59:14
问题 For example this line fails: $ nohup for i in mydir/*.fasta; do ./myscript.sh "$i"; done > output.txt& -bash: syntax error near unexpected token `do What's the right way to do it? 回答1: Because 'nohup' expects a single-word command and its arguments - not a shell loop construct. You'd have to use: nohup sh -c 'for i in mydir/*.fasta; do ./myscript.sh "$i"; done >output.txt' & 回答2: You can do it on one line, but you might want to do it tomorrow too. $ cat loopy.sh #!/bin/sh # a line of text