bash

gzip: stdout: File too large when running customized backup script

I've create a plain and siple backup script that only backs up certain files and folders. tar -zcf $DIRECTORY/var.www.tar.gz /var/www tar -zcf $DIRECTORY/development.tar.gz /development tar -zcf $DIRECTORY/home.tar.gz /home Now this script runs for about 30mins then gives me the following error gzip: stdout: File too large Any othe...

Listing the content of a tar file or a directory only down to some level

I wonder how to list the content of a tar file only down to some level? I understand tar tvf mytar.tar will list all files, but sometimes I would like to only see directories down to some level. Similarly, for the command ls, how do I control the level of subdirectories that will be displayed? By default, it will only show the direct ...

How to send a notification to another user with notify-send ? Bash

Hello all, notify-send display a notification box with the message that you want to display on your own machine. Is there a way to use notify-send to send a notification message to another user and display the message on his machine? Thanks ...

Remove first element from $@ in bash

I'm writing a bash script that needs to loop over the arguments passed into the script. However, the first argument shouldn't be looped over, and instead needs to be checked before the loop. If I didn't have to remove that first element I could just do: for item in "$@" ; do #process item done I could modify the loop to check if i...

Running an array of processes

I have the following array: procs=( 'one a b c' 'two d e f' 'three g h i' ) I try run these processes from a loop (using echo instead of eval so I can debug): for proc in ${procs[@]} do echo $proc done I get: one a b c two d e f three g h i I wanted: one a b c two d e f three g h i What went wrong? ...

How can I quickly sum all numbers in a file?

I have a file which contains several thousand numbers, each on it's own line: 34 42 11 6 2 99 ... I'm looking to write a script which will print the sum of all numbers in the file. I've got a solution, but it's not very efficient. (It takes several minutes to run.) I'm looking for a more efficient solution. Any suggestions? ...

Round all numbers in file to equal length in Bash?

Hello, Is there easy way how to round floating numbers in a file to equal length? The file contains other text not only numbers. before: bla bla bla 3.4689 bla bla bla 4.39223 bla. after: bla bla bla 3.47 bla bla bla 4.39 bla. Thanks ...

~/.irbrc not executed when starting irb or script/console

Here's what I've tried: 1. gem install awesome_print 2. echo "require 'ap'" >> ~/.irbrc 3. chmod u+x ~/.irbrc 4. script/console 5. ap { :test => 'value' } Result: NameError: undefined local variable or method `ap' for # ...

Is there a way to find the running time of the last executed command in the shell?

Is there a command like time that can display the running time details of the last or past executed commands on the shell? ...

How do you expand variables in UNIX/BASH?

Nested variables have prevented me from trying to use BASH more extensively... consider the following: export SYS_DIR='/home/${LOGNAME}/sys' export APP_DIR='${SYS_DIR}/app' I always end up with > set APP_DIR=/home/${LOGNAME}/sys/app why? lol and how do I get what I want =/ I'm not trying to resolve ${${var}}, but rather actual st...

What does the following line of a bash script do?

Usually work in Windows, but trying to setup RabbitMQ on my Mac. Can someone let me know what the line below does? [ "x" = "x$RABBITMQ_NODE_IP_ADDRESS" ] && [ "x" != "x$NODE_IP_ADDRESS" ] && RABBITMQ_NODE_IP_ADDRESS=${NODE_IP_ADDRESS} Specifically, I'm curious about the [ "x" = "x$RAB..."] syntax. ...

How Do I Pull Info from String

I am trying to pull dynamics from a load that I run using bash. I have gotten to a point where I get the string I want, now from this I want to pull certain information that can vary. The string that gets returned is as follows: Records: 2910 Deleted: 0 Skipped: 0 Warnings: 0 Each of the number can and will vary in length, but the o...

Preventing a child process (HandbrakeCLI) from causing the parent script to exit

I have a batch conversion script to turn .mkvs of various dimensions into ipod/iphone sized .mp4s, cropping/scaling to suit. Determining the original dimensions, required crop, output file is all working fine. However, on successful completion of the first conversion, HandbrakeCLI causes the parent script to exit. Why would this be? And ...

Bash script to replace spaces in file names

Can anyone recommend a safe solution to recursively replace spaces with underscores in file and directory names starting from a given root directory? For example, $ tree . |-- a dir | `-- file with spaces.txt `-- b dir |-- another file with spaces.txt `-- yet another file with spaces.pdf becomes $ tree . |-- a_dir | `--...

how to source a csh script in bash to set the enviroment

We have Oracle running on Solaris, and the shell is by default csh. So the login script sets the oracle_home, oracle_sid in csh also. But I don't like csh and want to use bash to do my work. So how to source the csh login script in bash? e.g, the following is what in the .cshrc file. And when use bash, I'd like use these variables. One ...

How to apply shell command to each line of a command output?

Suppose I have some output from a command (such as ls -1): a b c d e ... I want to apply a command (say echo) to each one, in turn. E.g. echo a echo b echo c echo d echo e ... What's the easiest way to do that in bash? ...

Data in linux FIFO seems lost

Hi, I have a bash script which wants to do some work in parallel, I did this by putting each job in an subshell which is run in the background. While the number of jobs running simultaneously should under some limit, I achieve this by first put some lines in a FIFO, then just before forking the subshell, the parent script is required to...

How to auto-restart a python script on fail?

This post describes how to keep a child process alive in a BASH script: http://stackoverflow.com/questions/696839/how-do-i-write-a-bash-script-to-restart-a-process-if-it-dies This worked great for calling another BASH script. However, I tried executing something similar where the child process is a Python script, daemon.py which crea...

[bash] checking wget's return value [if]

I'm writing a script to download a bunch of files, and I want it to inform when a particular file doesn't exist. r=`wget -q www.someurl.com` if [ $r -ne 0 ] then echo "Not there" else echo "OK" fi But it gives the following error on execution: ./file: line 2: [: -ne: unary operator expected What's wrong? ...

Setting up a 'find' command cron/bash script, which emails if there are any results?

I'd like to setup a cron job that checks e.g. every 24 hours to see if a 'find' command like the one below (which checks for malicious shell hacking scripts) has any results: find /home/username/public_html -type f -print0 | xargs -0 egrep '(\/tmp\/cmd(temp)?|SnIpEr_SA|(c99|r57|php)shell|milw0rm)' And if there are any results, then I ...