shell-scripting

How to detect ftp connection

Hi I'm using vsftpd and I want to write a shell script that will detect a connection to my server and send me an email with information who and when has logged in. I don't know where to start. Can someone point me in the right direction. Thanx ...

On mysqlimport, line breaks, and character encoding (I think)

First, some disclosure: I am not a Linux admin, and my Linux admin is not a programmer. That said, we have a cronjob that runs a mysqlimport command to import a text file that's generated daily. I have no control or involvement in how this file is created. Through trial and error, we discovered that the text file is generated on a Wi...

Executing shell scripts from a Java application independently

I have a java application consisting of a Thread that monitors a table in the database that contains shell scripts to be executed. I look up the database, every few seconds. for a script, execute it (via the Process class), and wait for another script in the table. My problem is: At times, some command in the script fails. The thread c...

sed: using variables across multiple lines

I am attempting to "grep" out bind for a specific user from an LDAP log file. The lines I need will be spread across multiple lines in the log. Here is example input: [2009/04/28 17:04:42.414] DoBind on connection 0x7c8affc0 [2009/04/28 17:04:42.414] Bind name:cn=admin,ou=appids,o=admineq, version:3, authentication:simple [2009/04/28 17...

What is the best (portable and maintanable) Shell Scripting language today?

Hi All, I know this question has kind-a started "religious" wars in past and there might not be one correct answer. But after working with ksh and csh for last 3-4 years and going through the pain of porting from one to another or applying a common piece of logic to multiple versions (read as legacy code), if I am writing a new script, ...

how to run shell script in mac os x everyday or set a timing?

at title how can i shell script in mac os x at a certain time,i know it is something related to cron but i cannot figure it out how to achieved can somebody provide some code ...

Grep Recursive and Count

Need to search a directories with lots of sub-directories for a string inside files: I'm using: grep -c -r "string here" * How can I total count of finds? How can I output to file only those files with at least one instance? ...

passing argument containing space in shell script

For some reason I need my script to be able to accept arguments with space characters. If for example I have a script as follows, for SOME_VAR in $@ do echo "$SOME_VAR" cd "$SOME_VAR" done; if I pass arguments to the script (assuming it is called foo.sh) sh foo.sh "Hello world" I am expecting the script to print Hello world...

Running the rpmbuild command with the --quiet option flag results in extensive debug info.

Hi all, I wish to minimize the output of my rpm build procedure. I run the following command: rpmbuild -ba --quiet "/tmp/yaneeve/kit/linux/rpm_spec" My system is: Linux yaneeve-lnx-82-5 2.4.21-47.ELsmp #1 SMP Wed Jul 5 20:38:41 EDT 2006 i686 i686 i386 GNU/Linux The rpmbuild version is: RPM version 4.2.3 The %prep section of my rpm s...

In Unix, how do I find out which executables or processes are using my shared libraries?

How do I find out which executables or processes are using my shared library objects in a Unix environment, specifically the AIX environment. Is there any command for it? ...

Bash condition of the form - [ -n "${VAR:-x}" ] gets evaluated even though VAR is set

Hi all, I have written an if statement of the form: if [ -n "${VAR:-x}" ]; then #do something export VAR=#something fi My shell script calls this statement twice and surprisingly passes the condition twice. [hint (perhaps...): This exact code is repeated in a function in an included file. The if statement is first evaluated pr...

How do I write a bash alias/function to grep all files in all subdirectories for a string?

I've been using the following command to grep for a string in all the python source files in and below my current directory: find . -name '*.py' -exec grep -nHr <string> {} \; I'd like to simplify things so that I can just type something like findpy <string> And get the exact same result. Aliases don't seem sufficient since they on...

How to find difference in csv record

Is there an algorithm or diff-like utilities to find difference between two csv files? Example: file1 ------- key1,value1 key2,value2 key3,value3 key5,value5 key7,value7 file2 ------- key1,value1 key3,value3 key4,value4 key5,value5 key6,value6 With this diff-like utilities it will output 3 types of records: Records that only exists...

Add up a column of numbers at the Unix shell

Given a list of files in files.txt, I can get a list of their sizes like this: cat files.txt | xargs ls -l | cut -c 23-30 which produces something like this: 151552 319488 1536000 225280 How can I get the total of all those numbers? ...

Shell Script: How to pass command line arguments to an UNIX alias?

How do I pass the command line arguments to an alias. Here is a sample: alias mkcd='mkdir $1; cd $1;' But in this case the $xx is getting translated at the alias creatin time and not at the runtime. I have, however, created a workaround using a shell function (after googling a little) like below: function mkcd(){ mkdir $1; cd...

Block Comments in a Shell Script

Is there a simple way to comment out a block of code in a shell script? Google has some suggestions but they all seem awkward and ugly. ...

How to debug a bash script?

Is there any way to debug a bash script? E.g something that prints a sort of execution log like "calling line 1", "calling line 2" etc. ...

Shell fragment to make sure only one instance a shell script runs at any given time

At a previous workplace we used to have a highly-refined bash function called run-only-once that we could write into any long-running shell script, and then call it at the start of the script, which would check to see whether the script was already running as another process, and if so exit with a notification to STDOUT. Does anyone hav...

Read content from file and find full file-name on disk

My problem is that I have a bunch of file names without the version appended (version keeps changing everytime). The file names are in a file in a particular sequence and I need to get the latest version from a folder and then sequentially install the same. The logic would be: scan a file with contents read a line from the file using t...

shell script to search attribute and store value along with filename

Looking out for a shell script which searches for an attribute (a string) in all the files in current directory and stores the attribute values along with the file name. e.g File1.txt abc xyz = "pqr" File2.txt abc xyz = "klm" Here File1 and File2 contains desired string "abc xyz" and have values "pqr" and "klm". I want result somet...