bash

count specific word in line in bash

i have variable such as "1,2,3,4" i want to count of commas in this text in bash any idea ? thanks for help ...

Run bash with redefined PS1 env variable

Hi, guys! I have written cpp aplication called MyShell that takes as the params some real shell name (generally bash) and its params. MyShell works as a wrapper for it. I need to change command prompting for the inner shell, specifically the PS1 environmental variable. I know how to do it command-line way using PS1 env var: $ PS1="[m...

bash: double or single bracket, parentheses, curly braces

Hi, I am confused by the usage of bracket, parentheses, curly braces in Bash, as well as the difference between their double or single forms. Is there a clear explanation? Thanks and regards! ...

embedding short python scripts inside a bash script

I'd like to embed the text of short python scripts inside of a bash script, for use in say, my .bash_profile. What's the best way to go about doing such a thing? The solution I have so far is to call the python interpreter with the -c option, and tell the interpreter to exec whatever it reads from stdin. From there, I can build simple t...

Get router mac (without system call for ARP) in Objective-C

Ok - I am writing a daemon in Objective C that checks the connected router mac address every 5 seconds. I am completely new to objective C, and I am looking for a better way to do what I'm already doing. I'm currently calling "arp -a" and parsing the results via "Task": NSTask *task; task = [[NSTask alloc] init]; [task setLaunchPath...

How to call getopts in bash multiple times...

I have a common library that I use from several scripts that parses command line options, however I also want my individual scripts to be able to process arguments as well... e.g. common.sh: function get_options { echo -e "in getoptions" echo $OPTIND while getopts ":ab:" optionName; do [ ... processing code ... ] ...

Verify a file exists over ssh

Hello, I am trying to test if a file exists over SSH using pexpect. I have got most of the code working but I need to catch the value so I can assert whether the file exists. The code I have done is below: def VersionID(): ssh_newkey = 'Are you sure you want to continue connecting' # my ssh command line p=pexpe...

Copy folder recursively, excluding some folders

I am trying to write a simple bash script that will copy the entire contents of a folder including hidden files and folders into another folder, but I want to exclude certain specific folders. How could I achieve this? ...

DTMF monitoring via multimon, awk and espeak

Hello, the question is: How to listen to the spoken DTMD digit every time the sound card capture one? The objective is radio controlling my pc and interfaces activities dialing dtmf tones via a hand-held transceiver. I used multimon to hear DTMF tones I tried to use awk to filter digits and proceed accordingly. For example, if I key...

How to set an alias inside a bash shell script

OSX: This works from the command line: alias ruby="/opt/local/bin/ruby1.9" but in side a shell script, it has no effect. I want to write a script that will switch between ruby 1.8 and ruby 1.9, so this needs to be a script - not in my profile. It appears "source script.sh" works, but "./script.sh". Why is this? How can I replicate...

Is there any way I could get this behavior with cURL?

I am testing one of my server implementations and was wondering if I could make curl get embedded content? I mean, when a browser loads a page, it downloads all associated content too... Can someone please tell me how to do this with curl? I don't mind if it dumps even the binary data onto the terminal... I am trying to benchmark my ser...

reading a file line by line from a shell script

I am facing a problem in a bash shell script. This script is supposed to execute another shell script (./script here) and the output of the script is redirected to a file(tmp). Then the file should be read line by line and for each of the lines the same script(./script) should be executed giving the line as argument and the result should...

ssh executes bash script with ksh because of user default shell which i cant modify

hi i want to execute bash script with ssh but when i try this it's using ksh to execute command because of user has default shell is ksh which i use with ssh i can't change user default shell so what trick can i do to execute my bash script with ssh ? ...

Bash: Copy a folder full of files and folders to an external hdd, but only if there is enough space to complete the copy.

I want to copy a folder from my X-Serve RAID to an external HDD on an X-Serve. Both disks are on the same server, so copying is fairly easy. I use the ditto command: ditto -rsrc /Volumes/WadXServeRaid/Users/ $destinationpath/Users/ However, I only want the copy to start if there is enough space on the destination disk. I know I can us...

Bash - How to call a function declared in a parent shell?

I am writing a bash script that calls functions declared in the parent shell, but it doesn't work. For example: $ function myfunc() { echo "Here in myfunc" ; } $ myfunc Here in myfunc $ cat test.sh #! /bin/bash echo "Here in the script" myfunc $ ./test.sh Here in the script ./test.sh: line 4: myfunc: command not found $ myfunc Here ...

Check if process is running

Hello, I am trying to check if a process is running. If it is running I want a return value of 'OK' and if not a return value of 'Not OK'. I can only use 'ps' without any other arguments attached (eg. ps -ef) if thats the correct term. The code I have is: if ps | grep file; then echo 'OK'; else echo 'NO'; fi The problem with this i...

passing bash variables to ssh

ssh pvuser@host '. ~pvuser/.profile;/opt/datamart/bin/resmgr -import segp -colNames "npath cond type" -line "~Thresholds~Transmission_Auto|_|$r|_|rule|_|"' I am having trouble trying to pass the variable $r to ssh in my bash script above. Thanks for help ...

Is it possible to get the transfer time in milliseconds using wget?

Generally, wget shows transfer time in seconds... Is there a way I can get it to show the time in milliseconds? ...

How to get linux console $COLUMNS and $ROWS from PHP cli?

I'm currently creating a new neat CLI library for PHP, and i'd like to figure out the width/height of the console it's running in. I've tried many things like digging through $_ENV, exec("echo $COLUMNS"), etc, but no result, while if i type echo $COLUMNS or $ROWS in bash commandline, it neatly displays the value. What do i need to do ...

Minimal linear regression program

Hi, I am running some calculations in an external machine and at the end I get X, Y pairs. I want to apply linear regression and obtain A, B, and R2. In this machine I can not install anything (it runs Linux) and has basic stuff installed on it, python, bash (of course), etc. I wonder what would be the best approach to use a script(pyt...