bash

How to propagate a signal through an arborescence of scripts ? Bash

I have an arborescence of scripts which are controlled by a main one I want to trap the signal ctrl-c in the main script and propagate it to the others The other scripts should trap this signal as well ( from the main script ) and do some clean-up ... I have tried to send kill -s SIGINT to the children, but they seem they are unable ...

Java's Scanner class: using left- and right buttons with Bash

I'm not too familiar with Linux/Bash, so I can't really find the right terms to search for. Take the snippet: public class Main { public static void main(String[] args) { java.util.Scanner keyboard = new java.util.Scanner(System.in); while(true) { System.out.print("$ "); String in = keyboard....

Splitting string into array upon token

I'm writing a script to perform an offsite rsync backup, and whenever the rsyncline recieves some output it goes into a single variable. I then want to split that variable into an array upon the ^M token, so that I can send them to two different logger-sessions (so I get them on seperate lines in the log). My current line to perform the...

Appending rather than overwriting files when moving

I have the following directory structure: +-archive +-a +-data.txt +-b +-data.txt +-incoming +-a +-data.txt +-c +-data.txt How do I do the equivalent of mv incoming/* archive/ but have the contents of the files in incoming appended to those in archive rather than overwrite them? ...

How many different ways are there to get variable value in bash?

I found these two: [root@~]# echo $i; 2 [root@~]# echo ${i}; 2 ...

Bash: Continue script if only one instance is running.

Hello, now this is embarrassing. I'm writing quick script and I can't figure out why this statement don't work. if [ $(pidof -x test.sh | wc -w) -eq 1 ]; then echo Passed; fi I also tried using back-ticks instead of $() but it still wouldn't work. Can you see what is wrong with it? pidof -x test.sh | wc -w returns 1 if I run it insi...

Making bash script to check connectivity and change connection if necessary. Help me improve it?

My connection is flaky, however I have a backup one. I made some bash script to check for connectivity and change connection if the present one is dead. Please help me improve them. The scripts almost works, except for not waiting long enough to receive an IP (it cycles to next step in the until loop too quick). Here goes: #!/bin/bash ...

Invoking shell from java, it complaints "stty: standard input: Invalid argument"

Hi, everybody. I invoked shell command by Process class of java and it gave "stty: standard input: Invalid argument" no matter the command is right or wrong (normal output of shell command is shown too). If I run the shell command in shell, no such error message shows. I can't figure out why. Command is something lik this {"/bin/csh", "...

How to login as another user and then log out in bash script?

Hi, I need to write a bash script to do something as another user and then return to the initial user... Suppose I run the following as root: #!/bin/bash USER=zaraza su - "${USER}" #do some stuff as zaraza ________ #here I should logout zaraza #continue doing things as root In the console I should write "exit", but in bash is a keywo...

running bash scripts in php

I have two computers. On the first computer I have apache running with all my web code. On the second computer I have large amounts of data stored with a retrieval script (the script usually takes hours to run). I am essentially creating a web UI to access this data without any time delay. so I call: exec("bash initial.bash"); this i...

How do you convert date taken from a bash script to milliseconds in a Java program?

I am writing a piece of code in Java that needs to take a time sent from a bash script and parse the time to milliseconds. When I check the millisecond conversion on the date everything is correct except for the month I have sent which is January instead of March. Here is the variable I create in the bash script, which later in the scr...

bash: expanding variables with spaces

I have a file called "physics 1b.sh". In bash, if i try x="physics 1b" grep "string" "$x".sh grep complains: grep: physics 1b: No such file or directory. However, when I do grep "string" physics\ 1b.sh It works fine. So I guess the problem is something to do with the variable not being expanded to include the backslash that gr...

Using inotify-tools and ruby to push uploads to Cloud Files - SOLVED

Hi Guys, I wrote a few scripts to monitor an uploads directory for changes, then capture the file uploaded/changed and push it to cloud files using a ruby script. This all works well 95% of the time, the only exception is that occasionally, ruby fails with a 'file does not exist' exception. I am assuming that the ruby 'push' script is ...

"tailing" a binary file based on string location using bash?

I've got a bunch of binary files, each containing an embedded string near the end of the file but at different places (only occurs once in each file). I need to extract the part of the file starting at the location of the string till the end of the file and dump it into a new file. eg. If the file's contents is "AWREDEDEDEXXXERESSDSDS...

Renaming and Moving Files in Bash or Perl

HI, I'm completely new to Bash and StackOverflow. I need to move a set of files (all contained in the same folder) to a target folder where files with the same name could already exist. In case a specific file exists, I need to rename the file before moving it, by appending for example an incremental integer to the file name. The exte...

bash: getting rid of '.' and '..' when looping over files that begin with '.' in a folder

I want to loop over the files that begin with '.' in directory x (x might be any path): $ for file in x/.* > do > echo -n $file" " > done x/. x/.. x/..a x/.b What is the best way to get rid of x/., and x/.. ? ...

How can I copy files with names containing spaces and UNICODE, when using a shell script?

I have a list of files that I'm trying to copy and move (using cp and mv) in a bash shell script. The problem that I'm running into, is that I can't get either command to recognize a huge number of files, seemingly because the filenames contain spaces and/or unicode characters. I couldn't find any switches to decode/re-encode these cha...

Bash: how to interrupt this script when there's a CTRL-C?

I wrote a tiny Bash script to find all the Mercurial changesets (starting from the tip) that contains the string passed in argument: #!/bin/bash CNT=$(hg tip | awk '{ print $2 }' | head -c 3) while [ $CNT -gt 0 ] do echo rev $CNT hg log -v -r$CNT | grep $1 let CNT=CNT-1 done If I interrupt it by hitting ctrl-c, mor...

Bash: evaluate a mathematical term?

echo 3+3 How can I evaluate such expressions in Bash, in this case to 6? ...

Save path to specific folder in shell script

I am working on a Bash shell script that does something like this: #!/bin/bash folder=/mnt mkdir $folder/folder-`date +%N` var1= Now i need to somehow get the full path for the newly created folder into var1. There is going to be created a lot of folders in /mnt so i need to be 100% sure that the path in var1 is pointing to precise...