bash

Add (collect) exit codes in bash

I need to depend on few separate executions in a script and don't want to bundle them all in an ugly 'if' statement. I would like to take the exit code '$?' of each execution and add it; at the end, if this value is over a threshold - I would like to execute a command. Pseudo code: ALLOWEDERROR=5 run_something RESULT=$? ..other things...

How can I copy all my disorganized files into a single directory? (on linux)

I have thousands of mp3s inside a complex folder structure which resides within a single folder. I would like to move all the mp3s into a single directory with no subfolders. I can think of a variety of ways of doing this using the find command but one problem will be duplicate file names. I don't want to replace files since I often hav...

Bash: how to traverse directory structure and execute commands?

I have split a large text file into a number of sets of smaller ones for performance testing that i'm doing. There are a number of directories like this: /home/brianly/output-02 (contains 2 files myfile.chunk.00 and myfile.chunk.01) /home/brianly/output-04 (contains 4 files...) /home/brianly/output-06 (contains 6 files...) It's import...

Is it possible to see output to stdout after disown and logout?

I have done this to that programe: ctrl-z disown -h %1 bg 1 then logout, Is it still possible for me to see what that programe outputs to stdout now? ...

how to replace the "disown" with "screen"?

ctrl-z disown -h %1 bg 1 logout ...

Check if a function exists from a bash script.

How can I determine if a function is already defined in a bash script? I am trying to make my .bash_login script portable between systems, so I want to add logic to only call a function if it exists. I want to add __git_ps1() to PS1 only if that function exists on that system. This funciton normally defined in git-completion.bash whic...

How to keep a file under N lines long?

I have a log that should have the latest N entries. There's no problem if the file is a bit bigger a few times. My first attempt is periodically running: tail -n 20 file.log > file.log Unfortunately, that just empties the file. I could: tail -n 20 file.log > .file.log; mv .file.log file.log However, that seems messy. Is there a be...

sed to replace random numbers

Hello, i need to let sed replace some url in alot of file each file has the following http://www.expample.com/file.php?id=xxxxxxx where xxxxx consist of random numbers , random depth in each file like file 1 _h**p://www.expample.com/file.php?id=xx file 2 _h**p://www.expample.com/file.php?id=xxxxxxxx etc thanks in advance ...

IDE / Emacs mode for Shell scripting in Bash/Sh, etc.

I use Emacs for shell scripts. I know I read somewhere there's some mode to make it easier (code completion, autocomplete, bracket matching, syntax highligting, check syntax) to write Shell scripts on Emacs but haven't been able to find it. In short, I would like to turn Emacs into a Bash IDE. Also, is there any other tool/IDE to make s...

define variable to hold non-current date in bash

The following command issued from a terminal gets me yesterday's date: date --date='1 day ago' +%Y/%m/%d I'm trying to write a bash script where the number of days is a command line arg. I'd like to be able to store the resulting date in another variable and use it later in my script. Thoughts? ...

how to scp across servers using bash?

Is it doable? ...

`ls` exit status

EDIT: nothing to see here!!! 127 return means the command wasn't found - had to give an absolute path to the command for some reason :/ (I didn't delete in case someone else has this problem) Is there a reference of return statuses for common Linux functions like ls? (it doesn't seem to be in the man pages, at least for ls). If not, can...

run command in parent shell from ruby

I'm trying to change the directory of the shell I start the ruby script form via the ruby script itself... My point is to build a little program to manage favorites directories and easily change among them. Here's what I did #!/usr/bin/ruby Dir.chdir("/Users/luca/mydir") and than tried executing it in many ways... my_script (this do...

Bash or Python to go backwards?

Hi, I have a text file which a lot of random occurrences of the string @STRING_A, and I would be interested in writing a short script which removes only some of them. Particularly one that scans the file and once it finds a line which starts with this string like @STRING_A then checks if 3 lines backwards there is another occurrence ...

Is it possible to make a bash file run as root in crontab?

I need that bash file to run periodically,and must as root. Is that kind of possible? [root@file nutch-0.9]# locate crontab /etc/crontab /etc/sysconfig/crontab /usr/bin/crontab /usr/share/man/man1/crontab.1.gz /usr/share/man/man1p/crontab.1p.gz /usr/share/man/man5/crontab.5.gz /usr/share/vim/vim71/syntax/crontab.vim [root@file nutch-0....

Can a bash function be used in different scripts?

I've got a function that I want to reference and use across different scripts. Is there any way to do this? I don't want to be re-writing the same function for different scripts. Thanks. ...

OSX Malicious Terminal Command (colon, brackets, curly brackets, apersand, etc)

Ok, so someone "challenged" me to enter this into my OSX Terminal, but I have no idea what it would do: WARNING to the reader: the following line can be harmful; do NOT enter it unless you know what you are doing: :(){ :|:& };: Any ideas? ...

How to check if gcc has failed, returned a warning, or succeeded? (in bash)

Hi. How would I go about checking whether gcc has succeeded in compiling a program, failed, or succeeded but with a warning? #!/bin/sh string=$(gcc helloworld.c -o helloworld) if [ string -n ]; then echo "Failure" else echo "Success!" fi This only checks whether it has succeeded or (failed or compiled with warnings). -n mea...

Using bash command line, how to add "import package.name.*;" to many java files?

I'm thinking of using find or grep to collect the files, and maybe sed to make the change, but what to do with the output? Or would it be better to use "argdo" in vim? Note: this question is asking for command line solutions, not IDE's. Answers and comments suggesting IDE's will be calmly, politely and serenely flagged. :-) ...

coming from bash, what windows scripting language to learn?

For work I am moving over to windows after being on linux for quite a while. I want to get some scripting skills going for administrative tasks in windows. I am quite good with bash, but bash's "libraries/tools" are missing a lot when it comes to windows. I see vbscript, wsh, powershell, cmd, jscript, etc and wondering what to learn, or ...