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

learn more… | top users | synonyms (1)

11
votes
14answers
23k 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 ...
10
votes
4answers
9k 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. ...
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 ...
5
votes
2answers
7k views

Writing to stdin of background process

I'm on an Ubuntu 10.04 box, and started a server in the background (myserver &) over ssh. It's been running fine, but I need a way to get at the server's stdin, as the only way to control the ...
12
votes
2answers
9k 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?
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
812 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
793 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 ...
8
votes
5answers
23k 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
1answer
500 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
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
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
909 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
176 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" ...
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 ...
11
votes
16answers
32k 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
3answers
7k 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
208 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 ...
4
votes
2answers
465 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 ...
4
votes
2answers
3k views

Unix separate multiple commands which has '&' (execute in background) in the end

To separate regular commands in Unix is to put semicolon in the end like this: cd /path/to/file;./someExecutable; But it seems not working for commands like this: ./myProgram1 > /dev/null & ...
3
votes
3answers
790 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
484 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
6answers
818 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
2answers
370 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 ...
2
votes
3answers
1k 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
5answers
2k 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?
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
1answer
323 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 ...
1
vote
2answers
481 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
202 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
120 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?
0
votes
2answers
177 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" ...
0
votes
2answers
177 views

how to manage dates in shell

emphasized textI have a file containing 14000 dates . I wrote a script to find the last 5 days , 26/03/2002:11:52:25 27/03/2002:11:52:25 29/03/2002:11:30:41 30/03/2002:11:30:41 26/03/2002:11:30:41 ...
0
votes
2answers
2k views

Editing .bash_profile file not taking effect

I need to put export PATH=$PATH:/opt/lampp/bin to my ~/.bash_profile file so that mysql from command line works on my system. Please check mysql command line not working for further details on that. ...
0
votes
3answers
2k views

Changes to /etc/bashrc?

Are there any changes you make to the default bash reconfiguration script that would be helpful for others to know? Note that /etc/bashrc affects all users, where a .bashrc in a user's home directory ...
6
votes
3answers
2k views

echo based on grep result

I need a one liner which displays 'yes' or 'no' whether grep finds any results. I have played with grep -c, but without success.
5
votes
1answer
640 views

What's the difference between “sudo su -” and “sudo -i”? [duplicate]

Possible Duplicate: What is the difference between sudo -i and sudo su - I know both commands result in gaining a root-shell. But there are some differences. On some servers e.g. the prompt ...
5
votes
2answers
230 views

Any repercussions from not using default primary groups for Linux users?

We were thinking of not using the default primary group for our RHEL users. What I mean by default: User: melbin Primary group: melbin We will instead do something like: User: melbin Primary ...
5
votes
2answers
1k views

Bash: menu-complete only for few matches

With Bash auto-completion, is there a way to cycle through matches using menu-complete only if there are 1-2 options, and use listing with complete otherwise? Example home directory contains ...
4
votes
3answers
1k views

Possible to ignore the users shell in “su” command?

If I do su - -c 'mkdir bin' user1 then I get su: /usr/bin/ksh: No such file or directory because the users shell is set to ksh in /etc/passwd and ksh is not installed. Question How do I carry ...
4
votes
1answer
658 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 ...
3
votes
1answer
170 views

shell script (KSH) + set file to param & perform test between param and string

in my linux machine red-hat 5.1 - in ppp file - I have only the signature.pl string !!! remark - third application write the signature.pl string in to ppp file I set ppp file in $a param And ...
3
votes
6answers
2k views

BASH script that tests for IP

Is there an elegant way to test an IP address in a BASH script? I could do ifconfig and narrow down the IP using sed/awk, but I think there is a simpler solution. My application is basically using ...
2
votes
4answers
237 views

Starting a script as another user

I've created a script in /etc/init.d/ which has to run several other scripts from other (non-root privileged) users from their home directories, as if they started them. I launch these scripts ...
2
votes
1answer
95 views

Locate devices within a building

The situation: Our company is spread between two floors in a building. Every employee has a laptop (macbook Air or MacbookPro) and an iPhone. We have static DHCP mappings and DNS resolution so every ...
2
votes
3answers
2k views

redirect temporarily STDOUT to another file descriptor, but still to screen

I'm making a script that executes some commands inside, and these commands show some output on STDOUT (and STDERR as well, but that's no problem). I need that my script generates a .tar.gz file to ...