sh

Running full commands through remote ssh [duplicate]

情到浓时终转凉″ 提交于 2019-12-29 17:37:41
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: how to use ssh to run shell script on a remote machine? I am trying to make a bash script that runs on my remote server's daily cron jobs to automatically login through ssh to another unix box, run a few commands and then leave. #!/bin/bash ssh machinehost.com -l admin -p 2222 "/usr/bin/find /share/Public/backups/set0 -mtime +14 | xargs rm -f; /usr/bin/find /share/Public/backups/set1 -mtime +4 | xargs rm -f;

Running full commands through remote ssh [duplicate]

我只是一个虾纸丫 提交于 2019-12-29 17:37:09
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: how to use ssh to run shell script on a remote machine? I am trying to make a bash script that runs on my remote server's daily cron jobs to automatically login through ssh to another unix box, run a few commands and then leave. #!/bin/bash ssh machinehost.com -l admin -p 2222 "/usr/bin/find /share/Public/backups/set0 -mtime +14 | xargs rm -f; /usr/bin/find /share/Public/backups/set1 -mtime +4 | xargs rm -f;

Use the result of a shell command in a conditional in a makefile

白昼怎懂夜的黑 提交于 2019-12-29 09:56:27
问题 I am trying to execute a command in a conditional in a makefile. I got it working in a shell: if [ -z "$(ls -A mydir)" ]; then \ echo "empty dir"; \ else \ echo "non-empty dir"; \ fi but if I try it in a makefile, "$(ls -A mydir)" expands to nothing whatever if asdf is empty or not: all: if [ -z "$(ls -A mydir)" ]; then \ echo "empty dir"; \ else \ echo "non-empty dir"; \ fi The ls command does not expand as I expect: $ mkdir mydir $ make if [ -z "" ]; then \ echo "empty dir"; \ else \ echo

“source” command in shell script not working [duplicate]

感情迁移 提交于 2019-12-29 07:17:09
问题 This question already has answers here : Difference between sh and bash (11 answers) Closed last year . I have a file to be sourced in Centos 7. It just works fine if I do : $ source set_puregev_env however, if I put this in a shell script, it doesn't work.. $ sh xRUN xRUN: line 3: source: set_puregev_env: file not found this is my shell script : xRUN #!/bin/bash source set_puregev_env can anyone tell me what I might be doing wrong, or missing? 回答1: source is a command implemented in bash,

POSIX sh equivalent for Bash’s printf %q

南楼画角 提交于 2019-12-28 05:33:24
问题 Suppose I have a #!/bin/sh script which can take a variety of positional parameters, some of which may include spaces, either/both kinds of quotes, etc. I want to iterate "$@" and for each argument either process it immediately somehow, or save it for later. At the end of the script I want to launch (perhaps exec ) another process, passing in some of these parameters with all special characters intact. If I were doing no processing on the parameters, othercmd "$@" would work fine, but I need

Cron jobs and random times, within given hours

有些话、适合烂在心里 提交于 2019-12-28 01:44:46
问题 I need the ability to run a PHP script 20 times a day at completely random times. I also want it to run only between 9am - 11pm. I'm familiar with creating cron jobs in linux. 回答1: If I understand what you're looking for, you'll need to do something a bit messy, like having a cron job that runs a bash script that randomizes the run times... Something like this: crontab: 0 9 * * * /path/to/bashscript and in /path/to/bashscript: #!/bin/bash maxdelay=$((14*60)) # 14 hours from 9am to 11pm,

How can I get the behavior of GNU's readlink -f on a Mac?

ε祈祈猫儿з 提交于 2019-12-27 10:28:42
问题 On Linux, the readlink utility accepts an option -f that follows additional links. This doesn't seem to work on Mac and possibly BSD based systems. What would the equivalent be? Here's some debug information: $ which readlink; readlink -f /usr/bin/readlink readlink: illegal option -f usage: readlink [-n] [file ...] 回答1: readlink -f does two things: It iterates along a sequence of symlinks until it finds an actual file. It returns that file's canonicalized name—i.e., its absolute pathname. If

What does set -e mean in a bash script?

自闭症网瘾萝莉.ら 提交于 2019-12-27 09:02:11
问题 I'm studying the content of this preinst file that the script executes before that package is unpacked from its Debian archive (.deb) file. The script has the following code: #!/bin/bash set -e # Automatically added by dh_installinit if [ "$1" = install ]; then if [ -d /usr/share/MyApplicationName ]; then echo "MyApplicationName is just installed" return 1 fi rm -Rf $HOME/.config/nautilus-actions/nautilus-actions.conf rm -Rf $HOME/.local/share/file-manager/actions/* fi # End automatically

Remove newlines between two words

让人想犯罪 __ 提交于 2019-12-25 18:56:17
问题 I have a file that looks like: name: charles key1: how are you? name: erika key2: I'm fine, thanks name: ... How could I remove the new lines that between "key\d+" and "name:"? It should look like this: name: charles key1: how are you? name: erika key2: I'm fine, thanks name: ... I'm trying to use sed or awk but without any success. Is there any way to clean that lines? Is there any way to remove the newlines between "key\d+:" and "\w+:"? 回答1: something like this? kent$ awk '/^key.:/{p=1}/

Remove newlines between two words

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 18:56:06
问题 I have a file that looks like: name: charles key1: how are you? name: erika key2: I'm fine, thanks name: ... How could I remove the new lines that between "key\d+" and "name:"? It should look like this: name: charles key1: how are you? name: erika key2: I'm fine, thanks name: ... I'm trying to use sed or awk but without any success. Is there any way to clean that lines? Is there any way to remove the newlines between "key\d+:" and "\w+:"? 回答1: something like this? kent$ awk '/^key.:/{p=1}/