bash

What is the difference between $@ and $* in shell scripts ?

In shell scripts, what is the difference between $@ and $* ? Which one is the preferred way to get the script arguments ? Are there differences between the different shell interpreters about this ? ...

Kill a 10 minute old zombie process in linux bash script

I've been tinkering with a regex answer by yukondude with little success. I'm trying to kill processes that are older than 10 minutes. I already know what the process IDs are. I'm looping over an array every 10 min to see if any lingering procs are around and need to be killed. Anybody have any quick thoughts on this? Thanks, Steve ps ...

Format stdin in bash

I have a multi-line string coming from another program that I want to convert to a SQL command. I was hoping that printf could help me, but it doesn't seem to work: echo -e '1\n2\n3'|printf 'SELECT %s INTO MyTable' I was hoping to see: SELECT '1 2 3' INTO MyTable But I got: SELECT INTO MyTable How can I get the %s to read s...

Joining multiple lines into one with bash

I would like to join the result of ls -1 into one line and delimit it with whatever i want. Are there any standard linux commands i can use to achieve this? ...

What is rc.status file in linux

Hi, I am creating a linux service , in the skeleton file it is mentioned that we need to run various rc commands(rc-status ,rc_reset) to update the service status. What does this actually mean. I have googled it but not able find many details. Can somebody help me ...

Setting PATH in Makefile run by eclipse

I have a Makefile which runs fine from a bash shell, but fails to run from Eclipse. This is because the path I am setting in my .bash_profile is not getting used. What is the best way of making this happen? Is there somewhere else I could put the path, to make sure it is invoked in non-interactive shells (which is I assume how eclipse i...

Source operator doesn't work inside parenthesis in bash

I'd like to include a config file in my bash script with 2 conditions: 1) the config file name is constructed on-the-fly and stored in variable, and 2) in case if config file doesn't exist, the script should fail: config.cfg: CONFIGURED=yes test.sh: #!/bin/sh $CFG=config.cfg echo Source command doesn't work here: [ -f $CFG ] && ( ...

Git Status Across Multiple Repositories on a Mac

I have been searching for a solution to this for a while and have not found quite what I need. I have several Git Repositories in a folder on my Mac (OSX 10.6) and would like a script or tool that will loop through all the repositories and let me know if any of them needs "commit"-ing. This is my structure Sites   /project1   /pro...

Get file name before the extension

I have some files in the same directory (in UNIX filesystem) that looks like: a.txt.name b.xml.name c.properties.name a.txt.name2 b.xml.name2 c.properties.name2 How do I get the string before the name or name2 part using some shell command? ie. the a.txt, b.xml, c.properties part? ...

search for a string , and add if it matches

I have a file that has 2 columns as given below.... 101 6 102 23 103 45 109 36 101 42 108 21 102 24 109 67 and so on...... I want to write a script that adds the values from 2nd column if their corresponding first column matches for example add all 2nd column values if it's 1st column is 101 add all 2nd column values...

Batch equivalent of Bash backticks

When working with Bash, I can put the output of one command into another command like so: my_command `echo Test` would be the same thing as my_command Test (Obviously, this is just a non-practical example.) I'm just wondering if you can do the same thing in Batch. ...

Using /dev/tcp instead of wget

Why does this work: exec 3<>/dev/tcp/www.google.com/80 echo -e "GET / HTTP/1.1\n\n">/dev/tcp/www.google.com/80 Is there a way to do it in one-line w/o using wget, curl, or some other library? ...

Shell script variable problem

Hi all, I'm trying to write a shell script to automate a job for me. But i'm currently stuck. Here's the problem : I have a variable named var1 (a decreasing number from 25 to 0 and another variable named var${var1} and this equals to some string. then when i try to call var${var1} in anywhere in script via echo it fails. I have tried...

kill a process in bash

How do I kill a process which is running in bash - for example, suppose I open a file: $ gedit file.txt is there any way within the command prompt to close it? This example is fairly trivial, since I could just close the window, but it seems to come up a bit, particularly when I mistype commands. Also is there any way to escape an...

linux user login/logout log for computer restriction

Hi ! I would like to know how to log the login and logout of a user : it would be a mean to measure how much time someone has been connected in a month so far. I know it's possible to use the command "last". But this command is based on a file that has a r/w permission for the user, hence the possibility to change these data. I would l...

Tee a Pipe Asynchronously

...

How to extract nested tar.gz files easily?

Hi, I need to extract tar.gz a file. It's about 950mb. It has another 23 tar.gz files in it. Each of those 23 tar.gz files has one tar file in them. My questions is how I can easily extract all of them? Is there a commandline tool that I can use? The structure is like the following: foo.tar.gz ├───bar1.tar.gz │ ├───foobar1.tar ├─...

Array in Bash Not Found

I am trying to declare an array in bash, but when the code is run it says it cannot find the array. I have tried to write out the declaration of the array in several different ways, but it seems no matter how I try to declare it I cannot get it to work. I originally tried to declare it as such: candidate[1]= 0 candidate[2]= 0 candidate[...

Accessing variable from ARGV

I'm writing a cPanel postwwwact script, if you're not familiar with the script its run after a new account is created. it relies on the user account variable being passed to the script which i then use for various things (creating databases etc). However, I can't seem to find the right way to access the variable i want. I'm not that good...

Processing a tab delimited file with shell script processing

Hello, normally I would use Python/Perl for this procedure but I find myself (for political reasons) having to pull this off using a bash shell. I have a large tab delimited file that contains six columns and the second column is integers. I need to shell script a solution that would verify that the file indeed is six columns and that t...