bash

What's the difference between piping elements or specifying them as arguments in a Perl one-liner?

While learning Perl I am also learning Linux (Ubuntu), so it is kinda fire-hose sipping time around here. What is the difference between: find . -type f | perl -nle '... #aka yada yada' and perl -nle '... # same yada yada' `find . -type f` The first passes the file NAMES to Perl and the second passes the file CONTENTS it seems. ...

need to read data from a log... tail, grep and inotifywait

I have data on one server that comes into a continuously growing log file. I need to tail that log and grep some information and then send that to another server for php to insert into a database. The computer that has the log can't be allowed access to the database. I tried this so far but my syntax on the bash command is wrong and I ca...

Inserting text from a file to the beginning of another file - bash

Hi, I am trying to insert some copy-right information into the beginning of some source files. I know that using sed in the following way: sed "1iSome copyrighted information." sample.txt would insert the text "Some copyrighted information" to the beginning of sample.txt. I need to insert text from a file to the beginning of sample...

Bash script process name regex

I'm trying to regex process id's based on parts of a process name. It seems to work if I only do a single word, but it fails when I try to do something like: find me any process with path /beginning ** /endswiththis/ Here's what I have so far: QUEUE_PID="$(ps -ef | grep endswiththis | grep -v $0 | grep -v grep | awk '{ print $2 }')"; ...

Linux / Bash using PS -f for specific PID returns in different format than PS -f, also queston about using Grep to parse this

I have a need, for a python script I'm creating, to first get just the PID of a process (based on its name) and then to get from that process, usings its PID, its time duration, which, from the printout below, would be "00:00:00" root 5686 1 0 Sep23 ? 00:00:00 process-name I am using this to get just the PID, by the p...

How to get the modified environmental variables using c programme in Mac using bash terminal

Hi, I want to get the modified environment variables using C programme in Mac using bash terminal how to get it? if i use getenv i will get only the default system defined environment variables but i am not getting the modified one. how to get it ...

Shell Script (bash/ksh): 20 seconds to read a variable

Hi guys, I need to wait for an input for 20 seconds, after that myscript should continue the execution. I've tried using read -t20 var however this works only on bash. I'm using ksh on Solaris 10. Can someone help me please? EDIT: 20 seconds is only an example. Let's pretend it needs to wait for 1 hour. But the guy could or could not ...

Change working directory in shell with a python script

I want to implement a userland command that will take one of its arguments (path) and change the directory to that dir. After the program completion I would like the shell to be in that directory. So I want to implement cd command, but with external program. Can it be done in a python script or I have to write bash wrapper? Example: ...

bash evironment variables starting from a digit

I want to set an environment variable in bash, which starts from a digit. The environment of the process can contain such variables (it just doesn't care). But in the shell you have to create the variables, and then export them so they go to the environment. Is there a way to put some value into shell's environment without touching varia...

Coloring/indenting a script within script in Emacs

I often have shell scripts that call other scripting languages, like so: #!/bin/bash cat somefile|awk ' BEGIN { #This line is not auto-indented and is colored as a string constant. ... } { #Same with this line. ... }' echo "More Bash code here." ... Is there a way to make Emacs recognize the awk string as an awk program in...

question about command substitution and bashism

there are two different syntaxes for command substitution FOO=$(echo bar) and FOO=`echo bar` as far as i know, the first method is defined in bash, while the second is defined in sh. consider the following use of command substitution in an sh script #!/bin/sh FOO=$(echo bar) does that fall under the definition of bashism? b...

bash script regex to get directory path up nth levels

I'm using PWD to get the present working directory. Is there a SED or regex that I can use to, say, get the full path two parents up? ...

bash: Grab fields 5 and 7 from a Unix path?

Given paths like this: /data/mirrors/third-party/centos/5/projectA/x86_64 /data/mirrors/third-party/centos/5/projectA/i386 /data/mirrors/third-party/centos/5/projectA/noarch /data/mirrors/third-party/centos/4/projectB/x86_64 /data/mirrors/third-party/centos/4/projectB/i386 /data/mirrors/third-party/centos/4/projectB/noarch /data/mirrors...

Linux / Bash, using ps -o to get process by specific name?

I am trying to use the ps -o command to get just specific info about processes matching a certain name. However, I am having some issues on this, when I try to use this even to just get all processes, like so, it just returns a subset of what a normal ps -ef would return (it doesn't return nearly the same number of results so its not ret...

Bash: Split text-file into words with non-alphanumeric characters as delimiters

Lets say "textfile" contains the following: lorem$ipsum-is9simply the.dummy text%of-printing and that you want to print each word on a separate line. However, words should be defined not only by spaces, but by all non-alphanumeric characters. So the results should look like: lorem ipsum is9simply the dummy text of ...

Colors with unix command "watch"?

Some commands that I use display colors, but when I use them with watch the colors disappears: watch -n 1 node file.js Is it possible to have the colors back on somehow? ...

When do you use brace expansion?

I understood what brace expansion is. But I don't know where I use that. When do you use it? Please give me some convenient examples. Thanks. ...

An IDE for shell-scripting in windows environment.

I have learned shell-scripting in linux environment. Now I am unable to install Linux on my PC. I need to practice shell-scripting. Currently, I have Windows XP installed on my PC. Is there any known IDE which can help me practice shell-scripting programs in windows environment? Thanks in advance. ...

How do I get just real time value from 'time' command?

I would like to make a script that outputs only the real time value from the time command so I can plot the results. For example time command outputs real 1m0.001s user 1m0.000s sys 0m0.001s I want to write a script that outputs 60.001 How do I get just real time value from 'time' command in seconds? ...

How is the PATH env variable set when opening a BASH shell in Terminal.app on OS X?

What startup scripts—in the order that they are called—set the PATH variable when opening a BASH shell in Terminal.app on OS X? ...