sh

Shell Script Syntax Error: Unexpected End of File

落爺英雄遲暮 提交于 2019-11-28 20:07:36
In the following script I get an error: syntax error: unexpected end of file What is this error how can I resove it? It is pointing at the line whee the function is called. #!/bin/sh expected_diskusage="264" expected_dbconn="25" expected_httpdconn="20" expected_cpuusage="95" #expected_fd="100" httpdconn=`ps -ef|grep -i httpd|grep -v grep|wc -l` #httpd connections cpu_usage=`ps aux|awk 'NR > 0 { s +=$3 }; END {print s}'` disk_usage=`df -h|awk {'print $2'}|head -n3|awk 'NF{s=$0}END{print s}'` #db_connections=`mysql -uroot -pexxxxxx -s -N -e "show processlist"|wc -l` db_connections=6 cld_alert()

How do you delete all lines that begin with “string” in unix sh?

柔情痞子 提交于 2019-11-28 19:15:29
How do you delete all lines in a file that begin with "string" in sh? I was thinking about using the sed command. grep -v '^string' yourfile.txt > stripped.txt To do it in place, if your sed supports the -i option, you can do: sed -i '/^string/d' input-file sed and grep in your answers are missing their friend awk: awk '!/^string/' inputfile > resultfile You can use Vim in Ex mode: ex -sc g/^string/d -cx file g select all matching lines d delete x save and close 来源: https://stackoverflow.com/questions/8068203/how-do-you-delete-all-lines-that-begin-with-string-in-unix-sh

TERM environment variable not set

…衆ロ難τιáo~ 提交于 2019-11-28 19:05:48
I have a file.sh with this, when run show : TERM environment variable not set. smbmount //172.16.44.9/APPS/Interfas/HERRAM/sc5 /mnt/siscont5 -o iocharset=utf8,username=backup,password=backup2011,r if [ -f /mnt/siscont5/HER.TXT ]; then echo "No puedo actualizar ahora" umount /mnt/siscont5 else if [ ! -f /home/emni/siscont5/S5.TXT ]; then echo "Puedo actualizar... " touch /home/emni/siscont5/HER.TXT touch /mnt/siscont5/SC5.TXT mv -f /home/emni/siscont5/CCORPOSD.DBF /mnt/siscont5 mv -f /home/emni/siscont5/CCTRASD.DBF /mnt/siscont5 rm /mnt/siscont5/SC5.TXT rm /home/emni/siscont5/HER.TXT echo "La

How to copy and edit files in Android shell?

ぐ巨炮叔叔 提交于 2019-11-28 19:03:43
The Android shell does not have the cp command. Android shell also has no sed or grep or vi . I have no adb daemon available. There is mv command but it rejects to work if source is on a read-only device. What to do if I have to copy some directories from read-only device recursively? How to change a line in a text file (e.g. "PATH=/cache" to be "PATH=/mnt/asec") ? The most common answer to that is simple: Bundle few apps (busybox?) with your APK (assuming you want to use it within an application). As far as I know, the /data partition is not mounted noexec, and even if you don't want to

What's the meaning of a ! before a command in the shell?

醉酒当歌 提交于 2019-11-28 16:56:30
The question is in the title. What is the purpose of a shell command (part of a shell script) starting with an exclamation mark? Concrete example: In foo.sh: #!/usr/bin/env bash set -e ! docker stop foo ! docker rm -f foo # ... other stuff I know that without the space the exclamation mark is used for history replacements and ! <expression> according to the man page can be used to evaluate " True if expr is false ". But in the example context that does not make sense to me. TL;DR: This is just by-passing the set -e flag in the specific line where you are using it. Adding add to hek2mgl's

Shell: redirect stdout to /dev/null and stderr to stdout [duplicate]

99封情书 提交于 2019-11-28 16:39:20
This question already has an answer here: How to pipe stderr, and not stdout? 12 answers I saw this interesting question at a comment on cyberciti.biz . That I found I even can't find a flexible way to do this in one-line command with sh. As far my thought for the solution is: tmp_file=`mktemp` (./script 2>$tmp_file >/dev/null; cat $tmp_file) | ./other-script rm tmp_file But you see, this is not synchronous, and fatally, it's so ugly. Welcome to share you mind about this. :) geirha You want ./script 2>&1 1>/dev/null | ./other-script The order here is important. Let's assume stdin (fd 0),

echo >&2 “some text” what does it mean in shell scripting

為{幸葍}努か 提交于 2019-11-28 16:25:16
问题 I have seen echo being used like this in many places: echo >&2 message text ... What does this mean? I understand 2>&1 , however, I am not sure how to interpret the usage above. Can anyone please explain? 回答1: To quickly explain what the others missed: echo "hey" >&2 > redirect standard output (implicit 1> ) & what comes next is a file descriptor, not a file (only for right hand side of > ) 2 stderr file descriptor number Redirect stdout from echo command to stderr . (If you were to use echo

How to extract the first two characters of a string in shell scripting?

北慕城南 提交于 2019-11-28 16:16:39
For example, given: USCAGoleta9311734.5021-120.1287855805 I want to extract just: US Probably the most efficient method, if you're using the bash shell (and you appear to be, based on your comments), is to use the sub-string variant of parameter expansion: pax> long="USCAGol.blah.blah.blah" pax> short="${long:0:2}" ; echo "${short}" US This will set short to be the first two characters of long . If long is shorter than two characters, short will be identical to it. This in-shell method is usually better if you're going to be doing it a lot (like 50,000 times per report as you mention) since

Multiline syntax for piping a heredoc; is this portable?

纵饮孤独 提交于 2019-11-28 15:50:29
I'm familiar with this syntax: cmd1 << EOF | cmd2 text EOF but just discovered that bash allows me to write: cmd1 << EOF | text EOF cmd2 (the heredoc is used as input to cmd1, and the output of cmd1 is piped to cmd2). This seems like a very odd syntax. Is it portable? Yes, the POSIX standard allows this. According to the 2008 version: The here-document shall be treated as a single word that begins after the next <newline> and continues until there is a line containing only the delimiter and a <newline> , with no <blank> characters in between. Then the next here-document starts, if there is one

Piping command output to tee but also save exit code of command [duplicate]

心已入冬 提交于 2019-11-28 15:29:27
This question already has an answer here: Pipe output and capture exit status in Bash 15 answers I have a shell script in which I wrap a command (mvn clean install), to redirect the output to a logfile. #!/bin/bash ... mvn clean install $@ | tee $logfile echo $? # Does not show the return code of mvn clean install Now if mvn clean install fails with an error, I want my wrapper shell script also fail with that error. But since I'm piping all the output to tee, I cannot access the return code of mvn clean install , so when I access $? afterwards, it's always 0 (since tee successes). I tried