New answers tagged

0

I am not sure what happened. I was able to change my start line to start program = "/bin/bash -c 'screen -dmS tsdns /root/ts3/tsdns/tsdnsserver 41144'" It now works for whatever reason


1

#!/usr/bin/env bash target_host=10.121.77.16 target_port=22 target_user=vagrant bastion_user=yourusername bastion_host=10.23.85.245 bastion_port=32780 scp -P $target_port -o ProxyCommand="ssh -o 'ForwardAgent yes' $bastion_user@$bastion_host -p $bastion_port 'ssh-add ~/.ssh/*.rsa && nc %h %p'" /tmp/x.txt $target_user@$target_host:/tmp/


2

I had the same problem (no shell usleep on Solaris) so I wrote my own thus: #include "stdio.h" int main(int argc, char **argv) { usleep(atoi(argv[1])); return 0; } Doesn't check arguments - I'd recommend a properly written one if you wanted to keep it but that (gcc usleep.c -o usleep) will get you out of a hole.


0

$dev is unset in two call to tc, # Make sure queueing discipline is enabled. tc qdisc add dev $dev root handle 1: htb 2>/dev/null || /bin/true tc qdisc add dev $dev handle ffff: ingress 2>/dev/null || /bin/true this resolv to tc qdisc add dev root handle 1: htb with most likely an error piped to /dev/null replace this line with # Make sure ...


0

ok, this solution is overkill for what i was originally trying to do, but i'm posting it here in case it's useful. i ended up using named pipes and chaining them through tee. took a bit of nutting out how to lay it out presentably, but here it is. my original approached used 1 temp file, this uses 3 named pipes, so this is a little over-engineered. but it ...


0

It would have been better if you had provided input and desired/actual output examples for your bash script also, but I'll have a go anyway. In the second example, you are absolutely getting piped/second/first, and there is no way you could get anything else. The executions of second and first are concurrent, but first is sleeping longer than second, so it ...


0

man date for whatever version of date your OS provides and use the correct switches to print (see man strftime), from from left to right, with a space between each, first the date: Day (Three letter abbreviation Mon-Tue-Wed...) followed by a comma ,, the month (Three letter abbreviation Jan Feb Mar ...) the year (4 digit notation 1970, 1971 ...) and then ...


0

I used the example from MestreLion and drafted the code below. All you need to do is update the options and actions in the first two sections. #!/bin/bash #title: menu.sh #description: Menu which allows multiple items to be selected #author: Nathan Davieau # Based on script from MestreLion #created: May 19 2016 #updated: ...


1

sed -i '/\$USERID>/d' /tmp/username.txt You have enclosed your sed expression in ' single quotes. This will stop the expansion of $USERID and cause it to be used as a string literal. You should enclose the sed expression in " double quotes to allow the variable expansion. File contains following lines The -i switch to grep ignores case. You can ...


0

OK, I never did figure out how to read while there is input but I did notice that there is a length in the header. So, I parse out the length and then read that number of characters: #!/bin/bash for i in {1..9} do read line done array=(${line}) length=${array[1]} read line read -n ${length:0:-1} line echo "$line" >> /home/ubuntu/test echo -e ...


0

you can write find part more efficient (make sense when you have large amount of files) find ${DIR_REMOTE} -type f -name "*.jpg" 2>/dev/null also you can strip carriage return chars (\r) with sed: find ${DIR_REMOTE} -type f -name "*.jpg" 2>/dev/null | sed 's/\r//g'


0

You don't need to do ${SSH_USER}@${SSH_HOST}:"$(echo $f)" in your SCP command. I'd expect that this should work fine: ${SSH_USER}@${SSH_HOST}:"${f}" EDIT: re-reading your answer below, if you were going to echo in the copy command you'd need to do echo -n to disable printing a newline at the end.


1

Ok - I think i have found the solution. I've replaced the scp with rsync and it shown me the full path (which, in this case, was ended by ascii-sequence #\015). It looks like scp was looking for a file /some-path/some-file.jpg\r, because for loop divided the lines by \n ssh -t allocates a pseudo-terminal, which returns windows-like line endings (\r\n), ...


0

Maybe run the long running command like this in a crontab? timeout -k 300 command


5

This is because the result of the *mysql* globbing depends on the content of the directory you are in. Your shell interprets the * character (unless you escape it or hide it in quotes) by trying to match it to file names in the directory. To illustrate, execute (in each of the directories in question) echo yum list installed '*mysql*' echo yum list ...


1

It's not the piping doing it. Part of your problem is your pager, less. By default it truncates at the same length as your terminal does. You can fix this by telling it not to do that: ps aux | less -S ps detects the window width and outputs to fit The man page has one way to bypass this: -w Use 132 columns to display information, instead of the ...


0

This shell script sanitizes a directory recursively, to make files portable between Linux/Windows and FAT/NTFS/exFAT. It removes control characters, /:*?"<>\| and some reserved Windows names like COM0. sanitize() { shopt -s extglob; filename=$(basename "$1") directory=$(dirname "$1") filename_clean=$(echo "$filename" | sed -e ...


2

You can use for instance: touch /root/test > /dev/null 2>&1 ; echo $? 0 touch /blablablaroot/test > /dev/null 2>&1 ; echo $? 1 Better if you add timeout to the command: timeout 15 touch /blablablaroot/test > /dev/null 2>&1 ; echo $? 1 I hope it helps.


0

You should investigate using the ipset module for this: http://ipset.netfilter.org/ Simply add all the IP addresses into a set, and then setup a single iptables rule which drops/rejects packets against that set. Also easy to manage as you can add, remove and empty the set easily, and generally modify it "on the fly", as and when required.


0

You can escape the opening bracket using \[. For the closing bracket, use []].


0

Wrong command output assign to variable, you are evaluating the string "hpssacli controller slot=4 physicaldrive all show | grep -c OK" with "4" This should work: #!/bin/bash okdevices="$(hpssacli controller slot=4 physicaldrive all show | grep -c OK)" if [ $okdevices -lt 4 ]; then echo "missing disk" fi


1

Finally it turned out that nfs was responsible. Client was v.4, while server v.3 and therefore, mount option sec=sys was necessary at the client part. Thanks to all who bothered.


0

You could use a Makefile in ~/.ssh: config: config.in config.app.in > $@ (for f in $+; do cat $$f; echo; done) | sed '$$ d' >> $@ config.app.in: (echo "# Generated with foobar.sh."; \ foobar.sh) > $@ .PHONY: config.app.in Then move your existing config to config.in and run make to generate ...


0

Try this one. The ln provides the test-and-set functionality. touch lock.$$.tmp if ln lock.$$.tmp lock.dat 2>/dev/null then echo "File is mine" else echo "Test and set failed" fi rm -f lock.$$.tmp


-1

Is it file or directory? If file, you can use simple command touch - if file exists, it just modify last access time. If file doesn't exists, is created.


5

Stealing an answer from various comments and links to [SO]. It seems there is a POSIX compliant method that doesn't involve mkdir as I mentioned in my original answer below set -o noclobber or set -C { > file ; } &> /dev/null This file and returns 0 or fails and returns non zero if file already exists. Original answer You'll have to use ...


0

With GNU bash 4: declare -i eighty_percent_ram_mb # set integer attribute while read -r a b c; do [[ $a =~ ^MemTotal: ]] && mem=$b; done < /proc/meminfo eighty_percent_ram_mb=$mem/100*80/1024


0

Someone just tweeted this to me! eighty_percent_ram_mb=$(free -m | awk 'NR==2{printf "%.0f\n", $2*0.8 }') I tried it and it worked.


3

eighty_percent_ram_mb=$(free -m | awk 'NR==2{printf "%d", $2*0.8 }') Should do the job :)


1

I would suggest executing the script from the sending side and using that to trigger the receive portion. There's no sense in starting a cron job on both ends... You can issue commands on your remote server from the local server using ssh.



Top 50 recent answers are included