bash

Capistrano :shell example

Hello experts. I'm currently using Capistrano to deploy my web application which works like a charm. In my new project I must execute a command from sudo /bin/bash shell. Is it possible for Capistrano to login to the machine as user X, run sudo /bin/bash, enter the password and then execute a command in the sudo shell? If yes, could yo...

How to create a backup of an POSTGRES DB using bash?

How to create a backup of an POSTGRES DB using bash? ...

How to chmod of subdirectories of a provided path (BASH)

I need a script that takes a single command line argument that is a directory path. The script should check the argument to determine if it is in fact a directory. If it is a directory, then the script should change the protection mode of any subdirectories located in it to 600. If the argument is not a directory, then an appropriate me...

Copying a Directory Tree File by File

My advisor frequently compiles a bunch of software into his /usr/local and then distributes his /usr/local as a tarball. I then extract the tarball onto our lab machines for our use. Until now, this has worked fine, we just replace the old /usr/local with the contents of the tarball. But I have started installing my own software on thes...

When backing up a postgres database I get prompted for a password

I'm busy backing up my postgres db, I run the following command pg_dump -d data -U postgres -h 127.0.0.1 -CdiOv > data.sql I however have one problem I get asked for the password, if I want to add this into a cron I do not want to get promted for the password. Is there any way to do this without the password prompt? ...

How to ask bash to wait for a result and send a SIGKILL when it get it ?

I want to use zbarcam but after reading a barcode, it doesn't stop. $ zbarcam | xvkbd -file - -window emacs EAN-13:6941428130969 CODE-128:3096140900557 Do you know how I can tell bash to kill zbarcam after printing on the stdout the first \n ? ...

git: a quick command to go to root of the working tree

I wanted a simple git command to go up to the "root" of the repository. I started with a script, but figured that I cannot change active directory of the shell, I had to do a function. Unfortunately, I cannot call it directly with the non-dash form "git root", for instance. function git-root() { if [ -d .git ]; then return 0 fi A...

Problem in running a script

i have unix shell script which is need to be run like below test_sh XYZ=KLMN the content of the script is #!/bin/ksh echo $XYZ for using the value of XYZ i have do set -k before i run the script. is there a way where i can do this without doint set -k before running the script. or is there something that i can do in the script...

problem in shell script

I am trying this option #!/bin/ksh echo $1 awk '{FS="=";print $2}' $1 and on the command line test_sh INSTANCE=VIJAY but awk is failing. Is there any problem here? Basically I need the value VIJAY passed on the command line. ...

BASH script passing stdin input to a program and giving control back to user input

(I looked everywhere for this, perhaps my googling skill is off today) I have a program that requires a handful of initialization cmds from stdin (and not through arguments). It'd be nice to move those commands into a script so when the script completes I can start keying the real work. So something like: cat initcmds.txt | myprogram.e...

List all leaf subdirectories in linux

Is there an easy way to list only directories under a given directory in Linux? To explain better, I can do: find mydir -type d which gives: mydir/src mydir/src/main mydir/bin mydir/bin/classes What I want instead is: mydir/src/main mydir/bin/classes I can do this in a bash script that loops over the lines and removes previous l...

bash and filenames with spaces

The following is a simple bash command line: grep -li 'regex' "filename with spaces" "filename" No problems. Also the following works just fine: grep -li 'regex' $(<listOfFiles.txt) where listOfFiles.txt contains a list of filenames to be grepped, one filename per line. The problem occurs when listOfFiles.txt contains filenames w...

Using $@ properly

I am trying to write a tiny script that accepts any number of command line arguments that prints out the rwx permissions for a file (not directory) What I have is file=$@ if [ -f $file ] ; then ls -l $file fi This accepts only one command line argument however. Thanks for any help. ...

Best tool in unix for viewing large files

I am a novice in unix. i am facing a problem in viewing big log files in unix using Vi tool. could you please suggest the best tool for fast viewing of big files on unix. Request you to post your own ways of viewing the big files on unix. appreciate your help:) ...

How to check for an exploding zip file in bash?

I have a bash shell script that unzips a zip file, and manipulates the resulting files. Because of the process, I expect all the content I am interested to be within a single folder like so: file.zip /file /contentFolder1 /contentFolder2 stuff1.txt stuff2.txt ... I've noticed users on Windows typically don't ...

Why does bash sometime not flush output of a python program to a file

I have a crontab job calling a python script and outputting to a file: python run.py &> current_date.log now sometimes when I do tail -f current_date.log I see the file filling up with the output, but other times the log file exists, but stays empty for a long time. I am sure that the python script is printing stuff right after it...

How do I use tr to substitute '--' string

I have an output: -- out1 -- out2 -- out3 I want to get the output: out1 out2 out3 I thought of using: tr '--' '' but it doesn't recognize '--' to be the first string I want to substitute. How do I solve this? ...

netcat "Connection refused" on localhost

I'm trying to get a value from a netcat connection started at a php file, but it dies with: localhost [127.0.0.1] 2000 (?) : Connection refused I don't know why but it works well if I ssh it as apache user (www-data), this is what I've done: 1) Start an endless loop serving a date with a little delay: $ (while true; do nc -l -p 2000...

matching a line with a literal asterisk "*" in grep

Tried $ echo "$STRING" | egrep "(\*)" and also $ echo "$STRING" | egrep '(\*)' and countless other variations. I just want to match a line that contains a literal asterisk anywhere in the line. ...

How can I split a file into a given number of parts in Perl? (On Unix)

I have several large files, each of which I want to chunk/split it in to predefined number of parts. Is there an efficient way to do it in Unix (e.g. via awk/sed/perl)? Also each file can have varied number of lines. File1.txt 20,300,055 lines File2.txt 10,033,221 lines etc... ...