bash

Awk/Sed: How to do a recursive find/replace of a string?

How to I find and replace every occurrence of: subdomainA.example.com with subdomainB.example.com in every text file under the /home/www/ directory tree (recursive find/replace). ...

How to create Cron job to backup MySQL and FTP backup to my backup server?

I want to setup a cron job to run so that it will automatically backup my MySQL database, while the database is running, and then FTP that backup to my backup server. I assume I can do this using a bash script. Anyone know of a good way to accomplish this? Thanks in advance. ...

Append to /etc/apt/sources.list

I'm creating some scripts to streamline application installations and I need to append to the end of /etc/apt/sources.list This code below append to files in ~ but not in /etc/apt/ echo "deb http://ppa.launchpad.net/person/ppa/ubuntu karmic main" >> /etc/apt/sources.list @meder I have tried these following commands with no luck: su...

Sorting and extracting of dirnames

There are a lot of directories named like web001 web002 ... web123 ... I want to extract a max-number from this set... Something like num="´find -name /dirname sort ... | tail´" with extracting. I have no ideas... Thank you ...

How to extract archive from this script (using tar)

Hi, I have absolutly no idea how to unpack the created archive. I give you the complete Script. A Debian based Distibution named Univention uses this to backup several files in an tar archive. The real archive is packed in an function. The main Content where they create the actual tar file is: cat "$TMPDIR/freeinfo.txt" >> "$TMPDIR/In...

Bash globbing - autoexpand for a few specific cases?

I understand that the wildcard * (by itself) will expand in such a way that it means "all non-hidden files in the current folder" with hidden files being those prefixed by a period. There are two use cases that I would think are useful, but I don't know how to properly do: How can you glob for... "All files in the current folder, incl...

BASH: Find highest numbered filename in a directory where names start with digits (ls, sed)

I have a directory with files that look like this: 001_something.php 002_something_else.php 004_xyz.php 005_do_good_to_others.php I ultimately want to create a new, empty PHP file whose name starts with the next number in the series. LIST=`exec ls $MY_DIR | sed 's/\([0-9]\+\).*/\1/g' | tr '\n' ' '` The preceding code gives ...

Opening a new terminal tab in OSX(Snow Leopard) with the opening terminal windows directory path

Hi all. I've been Googling for a while looking for a simple way to do this, and I can't find one. I have a custom terminal environment set up (zsh) with various aliases and functions to make things easier. One thing I keep running into is that I will quickly APPLE-t to create a new tab and then type a command relative to the path of th...

Shell Scripting: Using bash with xargs

I'm trying to write a bash command that will delete all files matching a specific pattern - in this case, it's all of the old vmware log files that have built up. I've tried this command: find . -name vmware-*.log | xargs rm However, when I run the command, it chokes up on all of the folders that have spaces in their names. Is there ...

PowerShell eye for the Bash guy

For someone who has been using bash for years, what's the quickest way to get productive with Microsoft's PowerShell? I've noticed my old friends ls and ps work, but sadly grep didn't. I could just man up and read through the piles of documentation, but I'm guessing there is a quicker path to productivity for someone with a long histor...

How to supply many argv and outputredirection with one bash var ?

In file a.lst: in1.a in1.b > out1.a 2> out1.b in2.a in2.b > out2.a 2> out2.b In do.sh: CLI=$(sed -n -e "1 p" a.lst) perl a.pl $CLI I want to run like perl a.pl in1.a in1.b > out1.a 2> out1.b, how can I make it work ? ...

How to programmatically determine the current checked out Git branch

In a Unix or GNU scripting environment (e.g. a Linux distro, Cygwin, OSX), what is the best way to determine which Git branch is currently checked out in a working directory? One use of this technique would be automatically labeling a release (like svnversion would do with Subversion). Please also see my related question: How to progra...

How to programmatically determine whether the Git checkout is a tag and if so, what is the tag name

In a Unix or GNU scripting environment (e.g. a Linux distro, Cygwin, OSX), what is the best way to determine whether the current checkout is a Git tag. If it is a tag, how can I determine the tag name? One use of this technique would be automatically labeling a release (like svnversion would do with Subversion). See my related question...

graceful degradation for globbing on terminal

Whenever glob pattern match fails, it stops the whole job. For instance, $ mv *.jpg *.png folder1 && blahblah mv: cannot stat `*.jpg': No such file or directory *.png isn't moved to folder1 and blahblah is not run. And the script below works only for the case when both .[A-z]* and * succeed. #!/bin/bash cd $1 du -sk .[A-z]* *| sort...

Is there a command shell (like bash) view for Eclipse?

I am coding in Eclipse (on the Mac) and need to run OS shell commands from time to time. I have a lot of bash terminal windows open and it takes time and is distracting to find the right one for the programming session. The commands are not always the same, and I need to see the output, so something like an External Builder will not do...

Regex match a string with spaces (use quotes?) in an if statement

How would I do a regex match as shown below but with quotes around the ("^This") as in the real world "This" will be a string that can have spaces in it. #!/bin/bash text="This is just a test string" if [[ "$text" =~ ^This ]]; then echo "matched" else echo "not matched" fi I want to do something like if [[ "$text" =~ "^This ...

bash : Make job every x days

I have a bash script runned every day via cron. In this bash I want to run some command but only every x day (x is fixed and will be 3, 4 or 5 I don't know at the moment) I can test if the remainder of the division day of month / x equal 0 day_of_month % x = 0 I will work on a single month but not always between to month, for example...

Looking for recommendations on a good ** beginners ** bash tutorial

Hi, I am an ETL developer by profession that just started reading The Pragmatic Programmer by Dave Thomas & Andrew Hunt. I have been meaning to learn more about bash & command line in Ubuntu for a while but reading this book made me realize how essential it is for me to start learning it. Therefore, I would love to get some recommendati...

How to calculate a hash for a string (url) in bash for wget caching

I'm building a little tool that will download files using wget, reading the urls from different files. The same url may be present in different files; the url may even be present in one file several times. It would be inefficient to download a page several times (every time its url found in the list(s)). Thus, the simple approach is to ...

Escaping whitespace within nested shell/perl scripts

I'm trying to run a perl script from within a bash script (I'll change this design later on, but for now, bear with me). The bash script receives the argument that it will run. The argument to the script is as follows: test.sh "myscript.pl -g \"Some Example\" -n 1 -p 45" within the bash script, I simple run the argument that was passe...