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

learn more… | top users | synonyms (1)

6
votes
2answers
7k views

Run a bash script after EC2 instance boots

I have a script on an EC2 instance that remotely starts another instance. Once this instance has fully loaded (finished booting) I want it to automatically run a bash script, what would be the best ...
6
votes
3answers
3k 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.
6
votes
3answers
1k views

User name before sudo

I got a script requiring sudo, but the script must set parameters according to the original user, such as: chown "${USER}:${USER}" dir If I set it under sudo, I just end up with chmod root:root, ...
6
votes
2answers
3k views

How can I retrieve the absolute filename in a shell script on Mac OS X?

I'd like to retrieve the absolute file name of the script file that's currently executed. Links should be resolved, too. On Linux, this seems to be done like this: $(readlink -mn "$0") but ...
6
votes
4answers
7k views

Is it possible to run a command on windows server from Linux?

I want to restore a sqlserver db backup on remote windows server from linux. I tired "net rpc" but there is nothing for execute a command or script on remote server.
6
votes
2answers
8k views

How to repeatedly call rsync until files are sucessfully transferred

I'm trying to syncronize files from a remote server that is not reliable, meaning the connection tends to fail "randomly" with rsync: connection unexpectedly closed Rsync is called with ...
6
votes
3answers
2k views

Possible to disable “You have new mail in /var/mail/root”?

I would like to disable the mailcheck in FreeBSD 9.1. My login shell is BASH, so I have tried to add unset MAILCHECK in /root/.bashrc and /root/.profile, but I still get those messages. Question ...
6
votes
2answers
3k views

rsync: How to exclude Dotfiles only in topmost directory?

When performing backups under Bash with rsync, I'm trying to exclude all dotfiles and hidden directories in the top directory, but not those in otherwise targeted directories. For example: /copyme.c ...
6
votes
2answers
2k views

Where do you share or find useful powershell, bash, batch, vbs, scripts?

I just wrote a quick little powershell script to make my life easier for a task that I was facing. I thought it would be nice to put it on the Internet, where someone else may also find it useful. The ...
6
votes
5answers
11k views

Check to see if a directory exists remotely (shell script)

Is there a way to see if a directory exists on a remote server? Perhaps there's a better way, but I'm writing an application deployment script, and I want to create a directory on a remote server if ...
6
votes
6answers
4k views

how to write a script that only acts on new log entries

I feel like this should be a simple thing but I am having a hard time figuring it out. I am trying to write a script that will monitor one of the apache log files and take some specific action. But ...
6
votes
2answers
406 views

Bash script parameters

I need to write a bash script, and would like it to parse unordered parameters of the format: scriptname --param1 <string> --param2 <string> --param3 <date> Is there a simple way ...
6
votes
1answer
3k views

Add server to known_hosts

I would like to add github.com to the known_hosts file from the command line as I am creating a puppet manifest to provision a remote server. I have tried: "ssh-keyscan -H github.com > ...
6
votes
3answers
5k views

Rsync seems incompatible with .bashrc (causes “is your shell clean?”)

It turns out rsync can't work with a remote server which has a .bashrc file? At local client i got when run rsync: protocol version mismatch -- is your shell clean? (see the rsync man page for an ...
6
votes
5answers
4k views

Different color prompts for different machines when using terminal/ssh?

I have 5 machines I constantly ssh into to do work. Its getting increasingly frustrating when I am issuing wrong commands on wrong boxes. Luckily I havent done anything bad yet. I wanted to know if ...
6
votes
3answers
4k views

Find out want partition a directory is located on in Linux?

Is there a way to find out what partition a directory in located in? I know I can use df to list partitions and mount points but I need to be able to find out what partition any directory is located ...
6
votes
3answers
5k views

How do I exclude a folder when performing file operations i.e. cp, mv, rm and chown etc. in Linux

How do you exclude a folder when performing file operations i.e. cp etc. I would currently use the wild card * to apply file operation to all, but I need to exclude one single folder. The command ...
6
votes
3answers
10k views

kill a screen (but not all screens)

I have multiple screens running on an Ubuntu server that are initiated as: screen -dmS screen1 cmd screen -dmS screen2 cmd etc... And I need to kill one screen, but not all of them. What is the ...
6
votes
1answer
2k views

Bash custom prompt breaking wrapping of long command lines

I have a custom bash prompt that colours my username, hostname and current working directory. The colours display correctly, however when I type a command line that needs to wrap, the terminal does ...
6
votes
3answers
2k views

UTF-8 and !# shell scripts

Is there a way to configure bash on Linux (red hat and ubuntu) to allow shell scripts to be encoded in UTF-8? I can't find a simple way to change just one little thing and have the whole system just ...
6
votes
1answer
261 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 ...
6
votes
6answers
12k views

(svn+ssh) getting bash to load my PATH over SSH

This problem comes up with me trying to make svnserve (Subversion server) available on a server through SSH. I compiled SVN and installed it in $HOME/bin. Local access to it (not through SSH) works ...
6
votes
6answers
4k views

Setting the Timezone with an automated script

I'm writing scripts to automate setting up new slicehost installations. In a perfect world, after I started the script, it would just run, with no attention from me. I have succeeded, with one ...
6
votes
1answer
268 views

How to start netcat in listening mode from another host?

I have a script where I would like to start nc in listening mode on 10.10.10.11, but I would like to do it from 10.10.10.10, where I have this script ssh -n 10.10.10.11 nc -l 8023 | mbuffer -s 128k ...
6
votes
3answers
6k views

iftop - how to generate text file with its output?

iftop is great tool to view almost live bandwidth usage distinguished by source-ip source-port destination-ip destination port. I'm using it to see which client's ip is using most bandwidth. Now I ...
6
votes
1answer
4k views

Launching a PHP daemon from an LSB init script w/ start-stop-daemon

I'm writing an lsb init script (admittedly something I've never done from scratch) that launches a php script that daemonizes itself. The php script starts off like so: #!/usr/bin/env php <?php ...
6
votes
4answers
2k views

How can one set a terminal's title with the 'tput' command?

I discovered through this answer that I've been setting terminal colours in my prompt in a naive way for years. I've now modified my .bashrc to use 'tput' commands to colourise various elements of my ...
6
votes
1answer
1k views

Debian SSH - Resizing terminal does not register with bash

We recently reinstalled our server due to a disk failure, and now we're having an issue with resizing terminals. We installed Debian 6.0.6. Symptoms When you resize a terminal, no ncurses-based apps ...
6
votes
3answers
938 views

Bash: how to know if the last command's output ends with a newline or not?

Most of the time the output of a command ends with the newline character. But sometimes it does not, so the next shell prompt is printed in the same line together with the output. Example: ...
6
votes
2answers
3k views

rotate nohup out file (nohup.log)

is there a 'native' way where i can rotate nohup out file ?
5
votes
5answers
18k views

Read the first line of a file using bash

Does anyone know of a simple one liner to read the first line of a file in bash?
5
votes
3answers
1k views

Why does 'pkill /?' kill my SSH session?

After running the following commands (bash) as root via SSH: pkill --help pkill -h pkill /? The first two commands didn't provide me any information, that's why ran the third (kinda ...
5
votes
9answers
7k views

Bash snippet to move all files in a directory into that directory

I have a directory with lots of files and directories in it. In order to tidy it up, I'm going to put all those files into a directory, so I was going to do something like this: $ ls | wc -l 123 $ ...
5
votes
9answers
1k views

Best practices to prevent 'rm -rf /' in bash scripts

It's well known fact that extra space in env.variable can lead to deletion of / directory in bash script. #!/bin/bash ... rm -rf /$MYPATH if $MYPATH contains values like " dir" or "dir /" it will ...
5
votes
4answers
4k views

How can I find the path to an executable in OSX

Is there a command I can use to easily find the path to an executable? I'm looking for identify on my local machine - something like pwd? pwd identify => /usr/local/bin/identify
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: ...
5
votes
3answers
2k views

Send message to IRC channel from bash

I have installed ircd-hybrid on my Ubuntu Server (192.168.1.2, example.com). We use #teamchannel to communicate inside the team. The question is: how can I send some short message from example.com to ...
5
votes
3answers
2k views

Bash command for regular expression substitution

What bash command can be used for regex substitution on a pipe? cat foo.txt | someprogram
5
votes
3answers
12k 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? ...
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 ...
5
votes
5answers
3k views

How to include all files from a directory in shell script (/etc/init.d/iptables in this case)

I have an /etc/init.d/iptables start|stop|restart script on different ubuntu servers (which is a normal shell script) For each new service I have to edit and insert a line to open a port. This leads ...
5
votes
3answers
367 views

Bash variable assignment using another variable as part

I have the following excerpt from a bash script used to backup a database #!/bin/bash DB=database_name DBUSER=username FILENAME=$DB_$(date +%s).sql I am trying to reuse the value of DB within the ...
5
votes
6answers
2k views

how do I make solaris shell more familiar for a linux user? [closed]

I've been a linux user for years. Very used to the bash shell, used to linux shell key mappings that come with most mainstream distros. I'm also a happy vim user in linux & love my arrow keys. ...
5
votes
3answers
3k views

Linux file copy with ETA?

I'm copying a large amount of files between disks. There's approximately 16 GB of data. I'd like to see progress information, and even an estimated time of completion from the command line. Any ...
5
votes
1answer
509 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
3answers
4k views

Determine if file is in the process of being written upon?

I need to deploy an automated process (via 1 min cron script) that looks for tar files in a specific directory. If a tar file is found, it is untarred to the appropriate location and then the tar file ...
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
3k views

On Redhat, what does “kernel.suid_dumpable = 1” mean?

I'm running a bash script to copy some log files and then restart a service on a Red Hat box. Every time I execute the script, I get the following on my console: [root@servername ~]# sh ...
5
votes
2answers
817 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 . ...
5
votes
4answers
3k views

Prompt customization: how to detect when there is no tty

I have a customized prompt with colors (using tput) and every time I start a non-interactive session in the server I get a bunch of errors. For instance if I start a non-interactive session like this: ...