bash

Create mysql backup from server, download locally with scp and replace mamp database

I'm creating a snippet to be used in my Mac OS X terminal (bash) which will allow me to do the following in one step: Log in to my server via ssh Create a mysqldump backup of my Wordpress database Download the backup file to my local harddrive Replace my local Mamp Pro mysql database The idea is to create a local version of my curren...

Send POST request with netcat

Hi, I have found this little script in PHP that send a simple request to twitter for update your status, I have tried this: http://pratham.name/twitter-php-script-without-curl.html, and it work. Now, I want send this request with netcat, but this doesn't work, why? I send request in this way: echo -e $head | nc twitter.com 80 The $he...

How to count lines on a document ?

Hey there ... I have lines like these, and I want to know how many lines I actually have... 09:16:39 AM all 2.00 0.00 4.00 0.00 0.00 0.00 0.00 0.00 94.00 09:16:40 AM all 5.00 0.00 0.00 4.00 0.00 0.00 0.00 0.00 91.00 09:16:41 AM all 0.00 0.00 4.00 0.00 0.00 0.00 ...

delete whitespace at the end of number format

Hi.. I have several line contains number like: XXXXXX.XXX (this number ended by whitespace.) How can I delete whitespace at the end of number format using sed? Thank for the help. ...

In Linux, how do I log a user out after idle period, even when they are still in a program

Hi all, I am trying to enforce a policy that logs an idle user out of a bash shell session, even when they are in an active process like a script-based menu, or vi session. I have tried using "export TMOUT=x" where x is the number of seconds, but this only logs a user out if they are idle at the bash shell prompt. Is there a bash scri...

sed regexp in a bash script

Hello! I want to extract a certain part of a string, if it exists. I'm interested in the xml filename, i.e i want whats between an "_" and ".xml". This is ok, it prints "555" MYSTRING=`echo "/sdd/ee/publ/xmlfile_555.xml" | sed 's/^.*_\([0-9]*\).xml/\1/'` echo "STRING = $MYSTRING" This is not ok because it returns the whole string. I...

How to use sed in a Makefile

I have tried putting the following in my Makefile: @if [ $(DEMO) -eq 0 ]; then \ cat sys.conf | sed -e "s#^public_demo[\s=].*$#public_demo=0#" >sys.conf.temp; \ else \ cat sys.conf | sed -e "s#^public_demo[\s=].*$#public_demo=1#" >sys.conf.temp; \ fi but when I run make, I get the following error: sed: -e expression #1, char ...

Duplicating stdout to stderr

I'd like to have the stdout of a command replicated to stderr as well under bash. Something like: $ echo "FooBar" (...) FooBar FooBar $ where (...) is the redirection expression. Is that possible? ...

Why do I have to use absolute path to execute bash scripts?

OK I have a bash script on my desktop called highest if I run: cd ~/Desktop highest I get: Command not found But if I run: ~/Desktop/highest It executes just fine. But why do I still need to use the absolute path when my command line is in the correct directory? I am guessing this has something to do with the $PATH variable? Lik...

Standard_in error in bash script

I have two bash scripts that are almost identical. One works and one doesn't and I can't figure out what's going on. Here are the scripts: This one works fine: #!/bin/bash CURDIR=$HOME/Documents/Development/road/Earthmoving TOL=0.05 echo -e "\nRunning Unit Tests" echo -e "------------------\n" for infile in $CURDIR/utest/*.csv do ...

List the files I own in subversion

So I have a bit of an issue. I work for a small startup (about 8 developers) and my boss recently decided that we need to put the owner of each file in the documentation. So I have been try to write something using svn blame and file to loop through every php file and see which files have my username on more that 15 lines, but I haven't ...

Bash scripting "common gotchas" for Python/Perl/Ruby programmers

Background: I grew up on using Perl/Python/Ruby for sysadmin-type tasks and shell scripting. I always avoided Bash scripting whenever I needed anything programmer-ish, like functions, looping or control structures. Back then, I could pick my favorite tool for whatever the job. Problem: Now I am working in a situation where the preferr...

convert a Perl code to a Bash code

May you convert this tiny code to Bash code : user/bin/perl sleep(300); system("killall -9 perl &"); sleep(5) Thanks in Advance . ...

Call a script shell from a java program with parametres

Hi! I would like to call this shell script: #!/bin/sh exiftool -a -u -g1 -j videos/$filename > metadata/$filename1.json; From a program in java. I try this: File dir = new File("videos"); String[] children = dir.list(); if (children == null) { // Either dir does not exist or is not a directory System.o...

How to start a linux shell as from /etc/inittab

We used to have two entries in our /etc/inittab: ::sysinit:/etc/init.d/rcS ttyS0::respawn:-/bin/sh rcS is a shell script which normally starts our application, but in a special case we called "return" to terminate it which apparently lets the /bin/sh take over the tty as we got a shell prompt where we could do some maintenance. Now t...

Run command from variables in shell script

I wrote this piece of code to scan a directory for files newer than a reference file while excluding specific subdirectories. #!/bin/bash dateMarker="date.marker" fileDate=$(date +%Y%m%d) excludedDirs=('./foo/bar' './foo/baz' './bar/baz') excludedDirsNum=${#excludedDirs[@]} for (( i=0; i < $excludedDirsNum; i++)); do myExcludes=${...

List only numeric file names in directory

I have a list of files with numeric file names (e.g. #.php, ##.php or ###.php) that I'd like to copy/move in one fell swoop. Does anyone know of an ls or grep combo command to accomplish this objective? I do have this much: ls -al | grep "[0-9].php" ...

Zip function for shell scripts

I'm trying to write a shell script that will make several targets into several different paths. I'll pass in a space-separated list of paths and a space-separated list of targets, and the script will make DESTDIR=$path $target for each pair of paths and targets. In Python, my script would look something like this: for path, target in zi...

Bash script doesn't set variable when run from script, but works fine from prompt

Why does the following work from the prompt but fail when stuck inside a bash script? The bash script produces one empty line leading me to believe the variable isn't being set: echo "red sox" | read my_var echo $my_var UPDATE: Since I guess my example isn't working, what I'm really trying to do is take I/O and pipe it into a variabl...

How do I exclude absolute paths for Tar ?

I am running a PHP script that gets me the absolute paths of files I want to tar up. This is the syntax I have: tar -cf tarname.tar -C /www/path/path/file1.txt /www/path/path2/path3/file2.xls when I untar it create the absolute path to the files. I do I get just /path with everything under it to show? ...