bash

gzipping up a set of directories and creating a tar compressed file

My bash fu is not what it should be. I want to create a little batch script which will copy a list of directories into a new zip file. There are (at least) two ways I can think of proving the list of files: read from a file (say config.txt). The file will contain the list of directories to zip up OR hard code the list directly into ...

extract arguments from function with scripting

I have a file with function prototypes like this: int func1(type1 arg, int x); type2 funct2(int z, char* buffer); I want to create a script (bash, sed, awk, whatever) that will print function = func1 // first argument type = type1// second argument type = int function = func1 // first argument type = int// second argument type =...

Dump memory of a process

Hi, When reading the /proc/$PID/maps you get the mapped memory regions. Is ther a way to dump one of this regions? $ cat /proc/18448/maps ...[snip]... 0059e000-005b1000 r-xp 00000000 08:11 40 /usr/local/lib/libgstlightning.so.0.0.0 005b1000-005b2000 r--p 00012000 08:11 40 /usr/local/lib/libgstlightning.so.0.0.0 005b200...

ftp getting last modified file by date

i am connecting remote server via ftp and i am sending ls -t command but it's outputting files sorted by name how can i get last modified file via ftp ? Note: i am connecting windows ftp server from linux machine ...

Directory of running script in Fish shell

I'm trying to get SBT running using the Fish shell. Below is the equivalent Bash script of what I'm trying to achieve: java -Xmx512M -jar `dirname $0`/sbt-launch.jar "$@" I see in the Fish documentation that $@ in Bash can be replaced with $argv in Fish. But I cannot see what to replace dirname $0 with. Does anyone know the equivale...

How to get the PID of a process in a pipeline

...

Can I rebind EOF in bash/Readline?

I'd like to unbind C-d from sending EOF in bash, and set it to another key. The idea is to keep C-d as EOF in my .bashrc, but to rebind it in my .bash_profile, so that hitting C-d repeatedly with pull me out of any subshells I'm in, but leave me in my login shell. Is this possible? C-d seems to be bound to delete-char, which it perfor...

A confusion about ${array[*]} versus ${array[@]} in the context of a Bash completion

I'm taking a stab at writing a Bash completion for the first time, and I'm a bit confused about about the two ways of dereferencing Bash arrays (${array[@]} and ${array[*]}). Here's the relevant chunk of code (it works, by the way, but I would like to understand it better): _switch() { local cur perls local ROOT=${PERLBREW_ROO...

How to flush a pipe using bash

I have a script that writes to a named pipe and another that reads from the pipe. Occasionally, when starting the script I have noticed that the contents of the pipe exist from a previous run of the script. Is there a way to flush out the pipe at the beginning of the script? ...

Bash script: set current working directory to the directory of the script

I'm writing a bash script (extremely unpleasant experience, as always) and I need the current working directory to act sanely. When I run the script from the directory in which it is in, it's fine. However, when I run it from somewhere else, the current working directory is for some reason propagated to the script. This is obviously u...

Open applications in different workspaces with Bash

Hi dear stackers, given I'm a lazy bastard, I tried to write a Bash script that opens at once some daily apps in different desktops. I've written that so far: #!/bin/bash firefox & thunderbird & /usr/bin/netbeans --locale en & amsn & gnome-terminal & sleep 2 wmctrl -r firefox -t 0 && wmctrl -r netbeans -t 1 && wmctrl -r gnome-terminal...

How to replace a few matches in one line using sed

How to replace a few matches in one line using sed? I have a file.log with text: sometext1;/somepath1/somepath_abc123/somepath3/file1.a;/somepath1/somepath_abc123/somepath3/file1.o;/somepath1/somepath_abc123/somepath3/file1.cpp; sometext2;/somepath1/somepath_abc123/somepath3/file2.a;/somepath/somepath_abc123/somepath3/file2.o;/somepat...

bash: output \n \t characters from mysql query

Hi there, I currently have $ echo "`echo "use joomla; describe jos_content" | mysql --batch -u root -ppassword`" and I would expect output that starts like this Field\tType\tNull\tKey\tDefault\tExtra\n but instead I get Field Type Null Key Default Extra I have tried all sorts of items at the moment. I could use mysql --h...

Bash: Chroot command passing 2 string parameters or better run a series of commands

I would like to do something like this: chroot /mount-point /path/to/script $var1 $var 2 Will this work? Will the chrooted Perl script be passed on these 2 parameters? If not, how to do this? Otherwise, is there any way to simply do chroot in the script, and then start doing commands such as perl script.pl $var1 $var2 etc? As I u...

Monster perl regex

I'm trying to change strings like this: <a href='../Example/case23.html'><img src='Blablabla.jpg' To this: <a href='../Example/case23.html'><img src='<?php imgname('case23'); ?>' And I've got this monster of a regular expression: find . -type f | xargs perl -pi -e \ 's/<a href=\'(.\.\.\/Example\/)(case\d\d)(.\.html\'><img src=\'...

Bash, compare files. Removing values from file A that exist in File B

Greetings, I have one file - more or less a greylisting file. I need to compare the 40 to 50 values in it against a whitelisting file - and remove any values from the greylist that exists in the whitelist file. Right now I'm taking each greylist value and comparing it against each value in the whitelisting file (which has 1 - 2 thousa...

Extra Copy of New Rsync Files

I am attempting to mirror a directory on a remote server using rsync. However, I would like a copy of all newly created files to be stored in a separate directory on the local machine. For example, if a new file is added on the remote server, I would like it to mirror regularly (for example, to ~/mirror), but save an additional copy of...

Execute a bash function upon entering a directory

I'd like to execute a particular bash function when I enter a new directory. Somethink like: alias cd="cd $@ && myfunction" $@ doesn't work there, and adding a backslash doesn't help. I'm also a little worried about messing with cd, and it would be nice if this worked for other commands which changed directory, like pushd and popd. A...

bash trickery using --init-file

I have a bash-script (let's call it /usr/bin/bosh) using the following she-bang line: #!/bin/bash --init-file It defines a couple of functions, and generally puts the interactive shell in an environment where the user can control a bunch of stuff that I want. This works pretty well. Now for the interesting part, I'd like to be able to...

What does this expression evaluate to? (bash shell script)

I am trying to do a code walk through a badly written bash script. I have come across this statement: FOOBAR_NAME=`date +WeekNo.%W` There are no prior declarations of any of the RHS variables in the script, lines preceding this statement. So my question is: What does FOOBAR_NAME resolve to, when it is used a few lines down in the s...