Bash is the Bourne Again SHell, the successor to the classic Unix sh (shell).

learn more… | top users | synonyms (1)

98
votes
9answers
37k views

Keeping a linux process running after I logout

I'm connecting to a Linux machine through SSH, and I'm trying to run a heavy bash script that makes filesystem operations. It's expected to keep running for hours, but I cannot leave the SSH session ...
0
votes
1answer
15 views

lvm clone logical volumes layout to another host

I want to clone LVM logical volume layout to another host ( = Create volumes with same size ). Does anyone know solution for this ? I know I can execute something like: sudo LC_ALL=C lvs -o ...
0
votes
0answers
34 views

Keep execution of bash script when aborted via CTRL+X or CTRL+C [migrated]

This is very nooby question I belive and I've tried everything to avoid asking it here, but I didn't found answere anywhere on whole internet. Go on and give me downvote but please answer me how to ...
8
votes
1answer
674 views

reboot multiple machines remotely

I need to reboot a number of machines remotely. Normally I just issue for host in <hostlist>;do ssh ${host} 'sudo shutdown -r now';done But I want give the users some time before the ...
0
votes
1answer
31 views

Can't seem to create file in bash

I'm trying to use this (under the root account) code in debian 7. #!/bin/bash cat > /root/.ssh/github.id_rsa << EOF -----BEGIN RSA PRIVATE KEY----- XYZ... -----END RSA PRIVATE KEY----- EOF ...
4
votes
0answers
64 views

How to securely quote an optional flag? [migrated]

If $FOO is set, I want to run: cd "$OUTPUTDIR" && fpm -s dir -t rpm \ -a x86_64 \ --epoch "${PKGEPOCH}" \ -n "${PACKAGENAME}" \ --version "${PKGVERSION}" \ --iteration ...
34
votes
8answers
8k views

How can I run arbitrarily complex command using sudo over ssh?

I have a system that I can only log in to under my username (myuser), but I need to run commands as other user (scriptuser). So far, I have come up with the following to run the commands I need: ssh ...
-2
votes
1answer
50 views

How do I install lvextend on CentOS?

lvextend did not come installed on my CentOS image, how do I install it? # lvextend -bash: lvextend: command not found
-3
votes
1answer
56 views

Are these Advanced Features possible with a Bash Script on an Ubuntu Server? [closed]

I am trying to build a really flexible and useful Server Backup Bash Script. I have pretty much no experience working or building Bash scripts. I know that thousands of them exist in the wild but I ...
0
votes
2answers
30 views

Creating a log file inside a script works when manually run, but not when run through cron

I'm using Percona's Xtrabackup tools to back up a database nightly. I wrote a wrapper script to keep the proper number of backups around, write the output to a log file, and email the log file if the ...
0
votes
0answers
16 views

How to (best) configure updatedb in cygwin to search windows shares?

Context: Finding Files Quickly Across the Network A confession. I'm more of a bash/linux developer type than a windows admin. Our deployments have over 80 servers. Recently a software bug required ...
0
votes
0answers
13 views

vim - “Press ENTER or type command to continue” right after loading only? [migrated]

Recently my vim has developed the habit of displaying Press ENTER or type command to continue the first time I do certain things right after I open it. For example, if I'm at my shell prompt and type ...
-3
votes
1answer
41 views

bash script mysql reset pass

It seems that this code is not working I tried using it on my debian 7 machine and the password it gives me is wrong. # Please confirm that you want to reset the MySQL passwords CONFIRM="n" echo -n ...
8
votes
4answers
16k views

How to remove invalid characters from filenames?

I have files with invalid characters like these 009_-_�%86ndringshåndtering.html It is a Æ where something have gone wrong in the filename. Is there a way to just remove all invalid characters? ...
0
votes
1answer
26 views

rsync not behaving the same in script vs shell

Afternoon ServerFault, I have hit a problem that I can seem to reach a solution to, I currently have a backup script that is meant to rsync VMs off our VMWare box onto our backup server, the problem ...
1
vote
5answers
2k views

Silent and scripted install of CPAN and Perl modules?

I need to install CPAN and some Perl modules automatically in a Scientific Linux (RHEL) installation script. Unfortunately the specific modules I want (at least one of them) cannot be found as RPM:s ...
0
votes
0answers
5 views

OS X LoginHook - nc exits prematurely for no apparent reason [migrated]

I'm trying to use loginhook to download large amounts of data and I've been having problems which I've nailed down to nc exiting prematurely for no apparent reason. This is a simplified test script: ...
0
votes
1answer
47 views

sudo: unable to execute … bad address - what is it and how to fix it?

I have a set of scripts which finishes up client machine deployment after executing a fairly generic NetRestore image. The main script runs under root privileges, and then calls another, "user" ...
1
vote
1answer
49 views

SSH issues: keyfile and host file not working as expected

When I login to server with a key ssh -i /home/me/.ssh/id_rsa server everything goes without glitch. The key is authorized on the server. However if I try to do same from a shell script, I get a ...
1
vote
2answers
2k views

How to execute a bash shell script via a browser link

I have written a bash script that periodically checks a directory for newly added .ear files and copies them to the respective JBoss server's deploy directory.Before copying, it checks if JBoss is ...
2
votes
5answers
2k views

user GPG key not able to be used by SUDO

I created a script that runs duplicity to backup files I have on a VPS,and uses a GPG key that I generated as a user. When I try and run this script as SUDO I get: GPGError: GPG Failed, see log ...
1
vote
2answers
254 views

Remote editing with diff / patch?

I do most of my work in vim. I much prefer to edit files using vim locally rather than sshing into a server and running vim there, for many reasons, one of the most important being UI responsiveness ...
4
votes
1answer
531 views

Will this HAProxy “restart script” work as gracefully I think it will?

I put this script together from various places. What I am hoping is that it will do the following once run: Pause all "NEW" http traffic for ports 80 and 443 - just "pause" them, don't give any ...
0
votes
1answer
21 views

How to act upon condition of whether a file updated via Rsync was updated

I think this is simple but I can't find anything in my googling, maybe I'm searching the wrong terms. I have a machine that syncs itself to another machine. If there are changes to a file on the ...
1
vote
0answers
45 views

How to make Supervisord read bash environment variables [closed]

I am using Supervisord to run my java application, which requires some environment variables for configuration. I am setting the environment variables in /etc/environment export ...
22
votes
5answers
18k views

What is “-bash: !”: event not found"

Try executing the following under a bash shell echo "Reboot your instance!" On my installation: root@domU-12-31-39-04-11-83:/usr/local/bin# bash --version GNU bash, version 4.1.5(1)-release ...
11
votes
6answers
1k views

SSH into a box with a frequently changed IP

I have some cloud boxes that change their IP frequently. I ssh using the hostname but have to edit the known_hosts file every time the server launches because of this error message: ...
0
votes
0answers
38 views

How to read/ modify freetds.conf (for ODBC) using augtool or similar in bash script?

How can I get augtool (augeas) or a similarly common tool to work with freetds.conf, so I can automate some configuration in a bash install script? This doesn't seem to work: augtool print ...
0
votes
3answers
87 views

postfix/dovecot - run script when mail is received

I need to implement solution on my postfix/dovecot server which will execute bash script every time message arrives. For this purpose I did following things in master.cf configuration myhook ...
10
votes
6answers
8k views

How can I execute a bash function with sudo?

I have a bash function defined in a global bashrc, which requires root privileges to work. How can I run it with sudo, e.g. sudo myfunction. By default it gives an error: sudo: myfunction: command ...
6
votes
6answers
12k views

What is a recommended way to patch the Shellshock Bash bug on an unsupported Ubuntu server?

I maintain an out-of-support Ubuntu 12.10 (Quantal Quetzal) server (don't ask me why, please), and we need to patch the Shellshock Bash security bug. As upgrades are not available anymore, what ...
1
vote
5answers
3k views

Don't need the whole line, just the match from regular expression

I simply need to get the match from a regular expression: $ cat myfile.txt | SOMETHING_HERE "/(\w).+/" The output has to be only what was matched, inside the parenthesis. Don't think I can use ...
4
votes
4answers
6k views

BASH Scripting, su to www-data for single command

I am working on automating the creation of subversion repositories and associated websites as described in this blog post I wrote. I am running into issues right around the part where I su to the ...
0
votes
4answers
4k views

Command does not execute in crontab while command itself works just fine

I have this script from Colin Johnson on Github - https://github.com/colinbjohnson/aws-missing-tools/tree/master/ec2-automate-backup It seems great. I have modified it to send email to myself every ...
3
votes
10answers
4k views

Delete all sub-directories except one

Suppose under the current directory, there are multiple sub-directories, and one is called A. How to delete all sub-directories except A with Bash?
0
votes
0answers
34 views

Is rbash secure if user login and ssh passwords are disabled?

I've got a server that I want to use as an SSH gateway for remote and local port forwarding. I don't want arbitrary commands to be able to be executed on it, only my scripts. I keep reading about how ...
7
votes
6answers
7k views

crontab environment

I have written various scripts to launch Java server applications, which are typically run for 24 hours before being shut down (by invoking the same script with a different parameter). The script ...
1
vote
3answers
2k views

Rsync Exit Code Checker - Bash

I have a simple script on my home server to sync data to my backup drive to be stored. Right now it runs multiple rsyncs one after another. Sometimes rsync fails on one or two of them. When this ...
0
votes
2answers
591 views

Why kill makes a bash script exit

after the kill statement the script prints "Terminated" and the following lines never get executed: #!/bin/bash kill -9 `ps -ef | grep MailSender | grep -v grep | awk '{print $2}'` echo starting ...
41
votes
12answers
55k views

What's the best way to check if a volume is mounted in a Bash script?

What's the best way to check if a volume is mounted in a Bash script? What I'd really like is a method that I can use like this: if <something is mounted at /mnt/foo> then <Do some ...
0
votes
0answers
37 views

Nagios plugin quits when encountering the bc command— how to diagnose?

I've written a nagios plugin using the bash scripting language. When I run this script by hand it works with no issue. Putting it into a nagios plugin however, using the same parameters, leads to ...
2
votes
1answer
48 views

How to exit after starting a service in Linux for loop

I have a for loop I'm using to stop and start number of development servers here is an example. for i in `cat hosts` ; do ssh $i -i .ssh/key.key -t sudo /etc/init.d/jboss-as start ; done This will ...
0
votes
1answer
45 views

Catch all emails and pipe them all to a script with postfix

I realize this question was asked and answer before. Here's what I have done. Created a catchall address and user. Here is my /etc/postfix/virtual file. @example.com catchall Added it to main.cf. ...
3
votes
2answers
3k views

How to delete empty source directories when moving folders with rsync?

rsync can be coaxed into moving folders very similarly and superiorly to traditional mv with the following options: rsync -axvvES --remove-source-files source_directory /destination/ However one ...
1
vote
1answer
25 views

Environment variable not available in python

I have a pretty interesting problem regarding environment variables, and googling around didn't show me any meaningful results: $ echo $BUCKET && python -c "import os; print ...
6
votes
3answers
1k views

How to recover from a deleted /bin/bash?

On my debian maschine I deleted /bin/bash by accident. Is there a way to get it back without reinstalltin the machine? If it helps. I'm still logged in. Guess once I'm out I cannot log in since it's ...
4
votes
7answers
3k views

Processing large files through bash pipes, does it buffer?

I need to use a command like the following: $ cat large.input.file | process.py > large.output.file The problem is, as this is won't the hard disk have a hard time jumping between reading the ...
0
votes
1answer
55 views

How can I tell a script is running under cron?

Is there a standard way to know if a shell script is running under cron as opposed to running from the command line. i.e. I'm thinking of running with more verbose output when manually kicked from the ...
-3
votes
1answer
78 views

Looking For Simple, Fast Incremental Backup Algorithm Using RSYNC [closed]

I'm running a simple bash script that uses rsync to do an incremental backup of my web server every hour. What I'm looking for is an efficient algorithm to delete the proper backups so that in the end ...
10
votes
5answers
29k views

Determine if filesystem or partition is mounted RO or RW via Bash Script?

Is there an easy way to determine if a mounted filesystem is mounted as Read-Only or Read-Write? I was thinking just to pipe mount but I thought there might be an easier way.