bash

Know any tricks for navigating the MySQL CLI?

For example, ^e jumps to the beginning, ^e jumps to the end, and ^w deletes the next word. ^l is clear, ^k deletes, ^j enters, ^b goes backwards... It seems similar to bash shortcuts but still somewhat different. ...

Hide/encrypt password in bash file to stop accidentally seeing it

Sorry if this has been asked before, I did check but couldn't find anything... Is there a function in Unix to encrypt and decrypt a password in a batch file so that I can pipe it into some other commands in a bash file? I realise that doing this provides no real security, it is more to stop someone accidentally seeing the password if t...

Writing a bash script from java

I have a java program that writes a bash script. Unfortunately when this script is saved, I need to modify it (ubuntu 10.04) to enable running it as an executable. Any way of circumventing this? I understand that it is a security thing... ...

how print all the attributes values of the title attributes in all my xml files

I wonder if anybode knows what command or bash-script-code I can use to print out all the values of the title attributes in all my xml files (in current directory). I'm using cygwin and have file names containing white spaces. ( I've been googling around and there are a lot of suggestions on downloading other utilities. If I can avo...

git hooks bash -- getting the commit message.

I am writing a git hook, to run on a commit to the main branch. I need it to parse and look for some text in the the commit message. How do I reference the commit message in my bash script? Also I would like to know how to run the hook only on commits to the main branch. so developers can quash there local commits and commit to the mai...

Shell Scripting: Using xargs to execute parallel instances of a shell function

I'm trying to use xargs in a shell script to run parallel instances of a function I've defined in the same script. The function times the fetching of a page, and so it's important that the pages are actually fetched concurrently in parallel processes, and not in background processes (if my understanding of this is wrong and there's negli...

Using bash shell inside Matlab

I'm trying to put a large set of bash commands into a matlab script and manage my variables (like file paths, parameters etc) from there. It is also needed because this workflow requires manual intervention at certain steps and I would like to use the step debugger for this. The problem is, I don't understand how matlab interfaces with ...

Perl-oneliner to bash

perl -E '$i=@{[`zypper lr`]}-2;map{`zypper rr $_`}1..$i' What would be a good way to write this perl-onliner in bash. ( I would like to remove all repositores with zypper)? ...

How to determine the current shell i'm working on ?

How to determine the current shell i am working on ? Does ps command output will alone do ? How to do this in different flavors of UNIX ? ...

Combining tab delimited files based on a column value

Suppose I have two tab-delimited files that share a column. Both files have a header line that gives a label to each column. What's an easy way to take the union of the two tables, i.e. take the columns from A and B, but do so according to the value of column K? for example, table A might be: employee_id name 123 john 124 mary a...

Why does the included code not work in bash?

DOWNLOAD_PATH="sample.ext" RATE_LIMIT="300K" mkdir ../$DOWNLOAD_PATH BASE_COMMAND="screen wget --continue --directory-prefix=../$DOWNLOAD_PATH --tries=2 --input-file=$DOWNLOAD_PATH" $("${BASE_COMMAND} --limit-rate=${RATE_LIMIT}") This does not work, but throws an error: line 5: screen wget --continue --directory-prefix=../sample.ext -...

bash script for copying files between directories.

I am writing the following script to copy *.nzb files to a folder to queue them for Download. I wrote the following script #!/bin/bash #This script copies NZB files from Downloads folder to HellaNZB queue folder. ${DOWN}="/home/myusuf3/Downloads/" ${QUEUE}="/home/myusuf3/.hellanzb/nzb/daemon.queue/" for a in $(find ${DOWN} -name ...

Cron jobs -- to run every 5 seconds

I want to create cron job that runs a script every 5 seconds. Seeing that cron jobs only allows increments of minutes 0-59 and so on. I thought to create another script that calls my original script written below. #!/bin/bash while true do # script in the same directory as this script. is this correct? bash makemehappy.sh sleep 1 don...

old rsync and spaces in filenames

Source directory is determined like so: SHOW=${PWD##*/} [email protected]:"/mnt/bigfish/video/TV/${SHOW}/" So it comes out something like: [email protected]:/mnt/bigfish/video/TV/The Name Of the Show With Spaces/ Then trying to run rsync like so: rsync -avz -e ssh "${SRC}" . But it tells me that ""/mnt/bigfish/video/TV/The" is...

bash: force exec'd process to have unbuffered stdout

I've got a script like: #!/bin/bash exec /usr/bin/some_binary > /tmp/my.log 2>&1 Problem is that some_binary sends all of its logging to stdout, and buffering makes it so that I only see output in chunks of a few lines. This is annoying when something gets stuck and I need to see what the last line says. Is there any way to make stdo...

Script to mail multiple files as independant email attachments

I'm looking to mail several pdf's that are located in a single directory via the mail command. Each email should only contain one PDF file as an attachment. Can you please provide a template on how to send each PDF via mail, one by one? Ideally Bash or AppleScript ...

List files with absolute path recursive in linux

Hey dudes, This question is quite similar to http://stackoverflow.com/questions/246215/how-can-i-list-files-with-their-absolute-path-in-linux I want to get the name of file or folder with absolute path and date modified. This command almost does it: ls -lR /foo/bar | awk '{print $6,$7,$8,$9}' But it doesnt show the absolute path. ...

How to "flip-replace" strings in a file using shell scripting

Hello, I am facing the following problem. Let's say I have a file, which contains something like this: blah blah blah blah more text <tag1>something</tag1> <tag2>something else</tag2> blah blah meh whatever foo bar What I want to do is to replace all occurrences of tag1 with tag2, and all occurences of tag2 with tag1. However, I don'...

multiple bash traps for the same signal

When I use the "trap" command in bash, the previous trap for the given signal is replaced. Is there a way of making more than one trap fire for the same signal? ...

find results piped to zcat and then to head

I'm trying to search for a certain string in a lot of gziped csv files, the string is located at the first row and my thought was to get the first row of each file by combining find, zcat and head. But I can't get them to work together. $find . -name "*.gz" -print | xargs zcat -f | head -1 20051114083300,1070074.00,0.00000000 xargs: zca...