Tag Info

Hot answers tagged

28

As stated by the error message, you have a syntax error in your command. It is due to the slightly surprising fact that & isn't part of a shell command but rather a separator between commands (like ; is). Though both are command separators & has an additional effect on the command on its left hand side. This certainly also confuse me sometimes, and I ...


4

a quick experiment: $ echo '{ "Comment": "comment", "test": { "enabled": true }, "enabled": true, "otherStuff": "blah", "otherStuff2": "blah", "otherStuff3": "blah" }' | jq '.enabled=false' { "otherStuff3": "blah", "otherStuff2": "blah", "otherStuff": "blah", "enabled": false, "test": { "enabled": true }, "Comment": ...


3

The reason is that although the echo statements go to STDOUT, and thus get sent through the pipe to tee, the "output" you're seeing from the wget command is on STDERR, which doesn't. This doesn't go through a pipe by default, going - as you saw - to tty instead. If you want to send both STDOUT and STDERR to a pipe's STDIN, you should use |&, eg ...


2

You can easily locate a package that contains a program yourself. Try: yum whatprovides */lvextend You'll then be told which package contains the file: lvm2-2.02.111-2.el6_6.1.x86_64 : Userland logical volume management tools Repo : updates Matched from: Filename : /sbin/lvextend And then you can install it: yum install lvm2


2

You can use sort only: sort -u dupl.txt > uniq.txt -u switch has the same effect like: sort dupl.txt | uniq > uniq.txt


2

If you sort the output before using uniq, it will work as desired. For example, I use the following kind of command all the time: cat access.log | grep "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" | sort | uniq -c | sort -n


2

In bash, you get the value of a variable with $directory. All the details in the manual. Unless you know specifically when to leave the quotes off, you should always quote "$variable" expansion. Also, [...] is not syntax, [ is actually a command (an alias for the test command). Commands must be separated from their arguments with spaces. if [ ...


2

You can limit logins via PAM settings: http://www.cyberciti.biz/tips/howto-deny-allow-linux-user-group-login.html


2

I don't think you can affect the exit code from find. You should perhaps look to capture the output from find and use that to determine if any files where found.


1

# ps -p $(netstat -tnp|awk '$6=="ESTABLISHED" {split($7,a,"/"); print a[1]}' | sort | uniq -c | sort -r | head -n 1 | awk '{print $2}') -o comm= skype


1

No that won't work. Input received over your TCP socket is not interpreted by xinetd so can't be passed as a commandline argument to your script. Your script will need to read whatever data is received as standard input e.g. #!/bin/bash read name echo "Hello $name"


1

I read the question as "in the shell" and not necessarily as "using only bash builtins". Try jsawk, which allows for manipulation and is scriptable, thought it relies on js as a dependency. If all you want to do is read a (unique) key from the JSON response, you could (adapted from Brendan OConnor): curl <destination> | grep -Po ...


1

The .ssh folder probably doesn't/didn't exist when you first ran the command. The safest thing to do is to add a command before the cat that checks/creates the folder: #!/bin/bash mkdir -p /root/.ssh chmod 700 /root/.ssh cat > /root/.ssh/github.id_rsa << EOF <some content> EOF chmod 600 /root/.ssh/github.id_rsa


1

Can you ssh on remote machine? If yes, you can write script remover.sh #!/bin/bash sshpass -p '********' ssh m***d@******.co.uk: "ls -t custom_backups/backup-*.sql | sed -n -e '31,1000 s#^#custom_backups/#p' | xargs rm -f" How it works? ls -t custom_backups/backup-*.sql List all files sorted by time - oldest last | sed -n -e '31,1000 ...


1

Everything is possible. But - not with pure bash - send e-mail with only bash, not sendmail is not trival ;) The same with sending files. Everything need external programs - bash can only control them. You must remember, that in various distributions can be different tools installed - for example mail command sometimes can add attachment to mails, sometimes ...


1

When running cmd over ssh in one line, the .profile is not read. To test, try this: ssh host env Use this instead to fix this issue (quotes are compulsory): ssh host '. ~/.profile; cmd' eg: ssh HOSTNAME '. ~/.bashrc; /var/www/example.com/dumper.sh'



Only top voted, non community-wiki answers of a minimum length are eligible