bash

creating symbolic link from select file type in a folder

i have a folder with many different types of files...but i want to create a symbolic link of only files that are of a certain file type (the data files with extension *.txt.mrg) in this case...i want to have the same file names for the symbolic links as the original files...how do i do this? i want to be able to create all the symbolic l...

How to pass all arguments passed to my bash script to a function of mine?

Let's say I have defined a function abc() that will handle all the logic related to analising the arguments passed to my script. How can I pass all arguments my bash script has received to it? The number of params is variable, so I can't just hardcode the arguments passed like this: abc $1 $2 $3 $4 edit: Better yet, is there any way ...

Doing parallel processing in bash?

I've thousands of png files which I like to make smaller with pngcrush. I've a simple find .. -exec job, but it's sequential. My machine has quite some resources and I'd make this in parallel. The operation to be performed on every png is: pngcrush input output && mv output input Ideally I can specify the maximum number of parallel o...

Problem with function arguments and for loop in bash

Why doesn't this print all the passed arguments, in bash? function abc() { echo "$1" #prints the correct argument for x in `seq 1 $#`; do echo "$x" #doesn't print the 1st, 2nd, etc arguments, but instead 1, 2, .. done } It is printing 1 2 3 4 ... instead. ...

cygwin + console2: running cygwin bash with startup dir

I am using Console2 as a bash wrapper on Windows. Most importantly, it enables me to start up a new bash tab in a predefined project directory. Now I would like to replace the Windows command line by a Cygwin bash. However, the "Startup Dir" setting in Console2 is not respected by Cygwin. Basically, I see three solution approaches: F...

Question on Cron entry

...

Order files by creation time to the millisecond in Bash

Hi there, I need to create a list of files which are located on my hard disk in order of when they arrived on the hard disk. To do so, I have used the following: ls -lat which lists all the files in date/time order, however, it only orders them to the nearest second. The problem here is that there are thousands of files and every so...

How do I run ruby commands in my bash script without getting "ruby: command not found"

my script= #!/bin/bash echo ************************BEGIN LOG******************************>>/root/backup_scripts/new_scripts/vmbackup.log 2>&1 date +"%m/%d/%Y %H:%M:%S $HOSTNAME">>/root/backup_scripts/new_scripts/vmbackup.log 2>&1 ruby /root/backup_scripts/new_scripts/aapxen01.rb>>/root/backup_scripts/new_scripts/vmbackup.log 2>&1 rub...

How to change shells in script

The default shell on the the system is csh but I want to write a script in bash. How do I write a script that will run bash and then convert back to csh at the end. I tried this but it doesn't work: bash var=Hello echo $var csh ...

Set default user variable in bash scripting

I am writing a bash shell script, run where the user is expected to pass a path into it as the $1 variable. How can I determine if $1 is missing and define a default value instead for it? ...

Remove file from different directory

How do I remove certain files from a different directory than $PWD using the bash shell script. Looking at the documentation for rm, it appears that rm only works in $PWD. Am I forced to use this method: oDir=$PWD cd directorytoremovefiles rm files cd oDir ...

How do I test if a perl command embedded in a bash script returns true?

So, I have a bash script inside of which I'd like to have a conditional which depends on what a perl script returns. The idea behind my code is as follows: for i in $(ls); do if $(perl -e "if (\$i =~ /^.*(bleh|blah|bluh)/) {print 'true';}"); then echo $i; fi; done Currently, this always returns true, and when I tried it ...

bash find subfolder and backup

How could I read the content of a parent folder and if sub-folders are found, then make a tar.gz files of those subfolders found. However, I know that subfolders will have the following filename format: name-1.2.3 What I want is to create a tar.gz file that looks like: name-1.2.3-20100928.tar.gz Any help will be appreciated. ...

Bash creating array's dynamically from a parsed string

I am trying to create nested array's dynamically from a string that has been parsed (parameter expansion) using a for loop in bash and I am failing: user@server:/home/user> foo=one,two,three user@server:/home/user> for i in ${foo//,/" "}; do echo ${i}; done one two three user@server:/home/user> for i in ${foo//,/" "}; do declare -a ${i}...

bash syntax error when using case statement

I have bash script that I use regularly in my job to automate a large job. I was making some changes today, but everything seemed fine. The script itself is about 1700 lines long. The first part of the script is all good and runs through all the user input and logic just fine. It then proceeds into the core of the script and stops wo...

Copy data from one database into another using bash

Hello, I need to copy data from one database into my own database, because i want to run it as a daily cronjob i prefer to have it in bash. I also need to store the values in variables so i can run various checks/validations on the values. This is what i got so far: echo "SELECT * FROM table WHERE value='ABC' AND value2 IS NULL ORDER B...

Bash / open a terminal with a command to run passed as an argument

Hi dear stackers, I created a script that starts all the apps I need for my day and assign them to the workspaces I want. Given I'm a extreme-lazy basterd, I'd like to know is there was a way to pass an argument to the terminal I open. The argument would be an alias that runs a massive source update of all the projects I'm working on....

How to do "tail this file until that process stops" in Bash?

I have a couple of scripts to control some applications (start/stop/list/etc). Currently my "stop" script just sends an interrupt signal to an application, but I'd like to have more feedback about what application does when it is shutting down. Ideally, I'd like to start tailing its log, then send an interrupt signal and then keep tailin...

Multiple instances of mysql client and stdin

Hi, I have several hosts from which i want to do the same query. So imagine, i have on each server the database db and a table test like : mysql> desc test; +-------+------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+------------------+------+-----+---------+-------+ ...

How to exit if a command failed ?

I am a noob in shell-scripting. I want to print a message and exit my script if a command fails. I've tried : my_command && (echo 'my_command failed; exit) but it does not work. It keeps executing the instructions following this line in the script. I'm using Ubuntu and bash. Thanks all. ...