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

learn more… | top users | synonyms (1)

67
votes
6answers
45k views

How to test if my server is vulnerable to the ShellShock bug?

How can I ensure my Bash installation is not vulnerable to the ShellShock bug anymore after the updates?
33
votes
8answers
5k 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 ...
30
votes
6answers
19k views

Merge 2 directory trees in Linux without copying?

I have two directory trees with similar layouts, i.e. . |-- dir1 | |-- a | | |-- file1.txt | | `-- file2.txt | |-- b | | `-- file3.txt | `-- c | `-- file4.txt `-- ...
37
votes
3answers
12k views

.profile vs. .bash_profile vs. .bashrc

what are the functional differences between these guys?
29
votes
8answers
25k views

How to make bash scripts print out every command before it executes?

For example, I have a simple bash file #!/bin/bash cd ~/hello ls How can I make it display every command before executing it? Just the opposite effect of "@echo off" in windows batch scripting.
34
votes
1answer
7k views

What is the difference between a 'Login' and an 'Interactive' bash shell

What is the difference between a ‘Login’ and an ‘Interactive’ bash shell? I have quoted Wikipedia below but can anybody give a better answer? EDIT: This is a community wiki so maybe rather than ...
13
votes
6answers
43k views

How can I edit the welcome message when ssh start?

I have a vps for my website hosting. It is running a ubuntu server. Every time I logged in my server by ssh, it displays a lengthy welcome message in my terminal. Linux node61.buyvm.net ...
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 ...
15
votes
4answers
12k views

run script as user who has nologin shell

All I need to do is to run a specific script as a particual user who does have the nologin/false shell indicated in /etc/passwd. I would run the script as root and this should run as another user. ...
7
votes
6answers
20k views

How should someone create an encrypted password for /etc/shadow?

I am setting up a new account on a Linux box for Subversion repository access, and can send the password to the new user. However, I think there was a command line utility for this new user to encrypt ...
12
votes
13answers
26k views

Stop ssh login from printing motd from the client?

I've got SSH passwordless set up, however it prints the MoTD when it logs in. Is there anyway to stop that happening from the client side? I've tried ssh -q but that doesn't work. I don't want to use ...
28
votes
3answers
4k views

Run command in bash without save in history

How to run command in bash without saving it in history?
13
votes
3answers
1k views

Strange bash history behaviour when running multiple sessions

How is command line history stored when I use multiple terminal windows? I know it is stored in .bash_history but I can't see the logic on what history is used if I open new window. It almost feels ...
12
votes
2answers
11k views

How to apply a filter to real time output of `tail -f `?

tail -f path The above will output modifications to the file instantly, but I want to apply a filter to the output, only show when there is a keyword xxx in it. How to approach this?
10
votes
5answers
26k 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.
5
votes
4answers
3k views

GNU screen loses (parts of) command histories

I use GNU screen with 5 different sessions, each of which stores its own command history. But often I don't find a command in the history, although I'm sure I've used it exactly in the session I'm ...
5
votes
2answers
2k views

Is there a way to configure bash to always page output?

I'd like to configure bash to page the output of all commands. Essentially, I want bash to behave as if every command I enter ended with '| less'. Is this possible?
5
votes
2answers
855 views

What is the purpose of each of the different UNIX/Linux shell startup files?

Previously, when setting up a *NIX environment for the first time, I would put all of my shell customisations into .bashrc, with the following .bash_profile: if [ -f $HOME/.bashrc ]; then . ...
2
votes
3answers
858 views

Bash completion dynamic behavior

I would like to have 2 different behavior of "tab" depending of the usage context. I would like to have the default behavior of bind '"\t":complete' any time except when users are trying to complete ...
7
votes
1answer
710 views

Where is $BASH_ENV usually set?

I have twin Linux servers that should be configured identically, however ssh commands to one of them are failing for commands that require a path that's specified in ~/.bashrc. For example, I can use ...
6
votes
6answers
3k views

In *nix, how to determine which filesystem a particular file is on?

In a generic, modern unix environment (say, GNU/Linux, GNU/Solaris, or Mac OS X), is there a good way to determine which mountpoint and filesystem-type a particular absolute file path is on? I ...
5
votes
1answer
545 views

how to pre-create directories on linux for file storage

looking for a way to pre-create directories on linux to be used to store a large number of files. We will be generating file ids using a GUID - I need to keep a copy of these files on a linux web ...
5
votes
8answers
3k views

Bash can't start a programme that's there and has all the right permissions

This is a gentoo server. There's a programme prog that can't execute. (Yes the execute permission is set) About the file $ ls prog $ ./prog bash: ./prog: No such file or directory $ file prog prog: ...
4
votes
5answers
1k views

Bash: Quotes getting stripped when a command is passed as argument to a function

I am trying to implement a dry run kind of mechanism for my script and facing the issue of quotes getting stripped off when a command is passed as an argument to a function and resulting in unexpected ...
3
votes
2answers
198 views

Writing an SVN hook that updates copy of committed code

I have a SVN repository with a lot of sub-projects stored in it. Right now in my post-commit I just loop through all possible folders on the machine and run svn update on each: REPOS="$1" REV="$2" ...
2
votes
5answers
3k views

Multithreaded downloading with shell script

Let's say I have a file with lots of URLs and I want to download them in parallel using arbitrary number of processes. How can I do it with bash?
1
vote
3answers
3k views

Appending a line to a file if it doesn't exist using Puppet

I've got a defined resource type to append a line to a file if it doesn't exist, as per below: define appendLineToFile($file, $line, $user) { exec { "echo \"\\n$line\" >> \"$file\"": ...
1
vote
3answers
1k views

Run FTP session from bash script

I'm trying to write a BASH script to test if an FTP site that I own is running. I therefore want the bash script to connect to the FTP site, log in with a dummy account and redirect the output to a ...
0
votes
1answer
290 views

Disable the ability to hide bash command history

User can hide the command history in bash by either append a space before the command unset HISTFILE How to disable this?
13
votes
16answers
36k views

Shell Command for Getting IP Address?

Is there a bash command to find the IP address for an Ubuntu box? I need to find the IP address so I can ssh into the machine later.
10
votes
5answers
9k views

Force SSH to use a specific shell

Is there any way to force SSH to use a particular shell on the remote end, regardless of what the user's default shell is? I've tried solutions akin to: ssh host.domain.com /bin/bash -c ...
6
votes
1answer
328 views

Providing normal users(non-root) with initialization and shutdown auto-run capabilities

I'm hosting an experimental/testing Linux box, running Debian Wheezy 7.4.0 distribution. Different users log into the machine over ssh to their accounts and are allowed to run the development tools ...
5
votes
6answers
11k 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 ...
5
votes
2answers
2k views

Start Unix screen, Run command, Detach

How can screen be used to start a new session and run a command within that session without killing that session? screen -S myScreenName runSomething I tried the above command and it says [screen ...
5
votes
2answers
808 views

How can I make bash to log shell commands to syslog?

Bash 4.1 is able to log the history to syslog. However I can't seem to make it work under FreeBSD 8. I've tried re-compiling bash from ports with -DWITH_SYSLOG= but to no avail. Has anyone managed to ...
4
votes
2answers
590 views

rsync not removing single quotes around array of strings --filter list

Trying to safely retrieve files from heavily infected Windows XP and 2003 machines that came to us from an acquisition. I have a similar need for automating a script that would run on PXE booted ...
3
votes
3answers
2k views

Log commands executed over ssh

I would like to log all commands executed over SSH. Say, ssh something@server.com COMMAND I want to log "COMMAND" on server.com I did search extensively but could not find anything. There is ...
3
votes
1answer
669 views

How to detect, in the guest operating system, if the vmware tools are out of date?

I'm trying to find a generic way of checking, in the guest operating system of a virtual machine, if the VMware Tools are out of date. The best way I have found so far has been to check the output of ...
3
votes
2answers
639 views

How do i use the {} operator in find execution inside exec

I tried this bash command: find /var/www/ -path '*wp-admin/index.php' -exec mv {} $(dirname {})/index_disabled But the second {} is not executed. It results in just ./index_disabled instead. How ...
3
votes
6answers
844 views

Any clever way to put a password in an SSH key?

My host uses passwords instead of id_rsa's to SSH in. But instead of typing the password everytime, is there a way to put the password in my .ssh/config ? For example: Host gravy_access Hostname ...
3
votes
2answers
3k views

Using rsync to rename files during copying with --files-from?

Using rsync, how can I rename files when copying with the --files-from argument? I have about 190,000 files, each of which need to be renamed when copying from source to destination. I plan to have ...
2
votes
1answer
88 views

Performing root mysql operations in bash scripts

What is a good practice to execute root operations on mysql databases in bash scripts? For example, I want to create new database and grant privileges, I have to use: mysql -u $ROOT -p"$ROOTPASS" -e ...
2
votes
3answers
2k views

How can I easily convert HTML special entities from a standard input stream in Linux?

CentOS Is there an easy way to convert HTML special entities from a data stream? I'm passing data to a bash script and sometimes that data includes special entities. For example: "test" ...
2
votes
4answers
5k views

How do I rename multiple files by removing characters in bash?

I have to rename multiple files in directory by removing first 5 characters for each filename. How can I do this i bash/shell? I'm using Ubuntu 11.10. Thanks.
2
votes
5answers
9k views

(Ubuntu) setuid bash doesn't work

Here is the code: (root:) # mkdir /test # cp /bin/bash /test/sbash # chmod a+s /test/sbash (user1:) $ cd /test $ ./sbash $ mkdir trycreate mkdir: cannot create directory `trycreate': Permission ...
2
votes
5answers
1k views

Shell command to remove files extension

I have a directory with automatically generated files that all end with the .sample extension. I would like to have a way to remove the .sample extension from them all in one terminal command. I ...
1
vote
2answers
614 views

Problems with bash variable expanding with single quotes

I have a variable that I build like this : ATTSTR="" for file in $LOCALDIR/*.pdf do ATTSTR="${ATTSTR} -a \"${file}\"" done The variable now contains (notice the whitespaces in the file name) : ...
1
vote
4answers
215 views

A script that verifies that Apache (or any account) has proper permission to navigate to a directory

It seems that Apache needs at least read and execute permission to all the sub-directories of a path in order to serve the files in the directory. Does anyone have a script or one-liner that could ...
0
votes
1answer
322 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
2answers
187 views

Executing SU in a bash script

I'm running a remote bash script (using ssh -t 'bash doscript.sh'). In "doscript.sh" I have a sudo su anotheruser. At that point, the script seems to push a shell and I'm left in that "interactive" ...