bash

Renaming files in a folder to sequential numbers

I'm looking for a simple script that renames the files in a directory to sequential numbers. Based on creation date of the files. For Example sadf.jpg to 0001.jpg, wrjr3.jpg to 0002.jpg and so on, the number of leading zeroes depending on the total amount of files (no need for extra zeroes if not needed). ...

How to find the size of file

FILE=a.txt FILE_SIZE = `stat -c %s $FILE` if [ $FILESIZE >= 1000 ]; then cp $FILE /tmp/ # How to empty file ? then I am trying to get size of file and if the size is over limited and cp those file and empty the same file How to acheive this ? ...

How to assign the parameter list "$@" to another variable?

In a shell script I want a variable p to be equal to "$@", so that the following two lines of code produce the same result: for x in "$p"; do echo $x; done for x in "$@"; do echo $x; done If I do p=$@ or p="$@" this doesn't work. When the command line arguments have spaces in their names, I can't find a simple workaround to this prob...

in my bash loop over a list of some servers, if the ssh connects the bash script exits

I have a quick script to run a command on each server using ssh (i am sure there are lots of better ways to do this, but it was intended to just work quick!!). For the test1 etc, there is no server so the script continues, the script also continues if the pubkey auth fails. However if the script connects, the date is printed but the ssh ...

Can a bash script tell if it's being run via cron?

Hello all, Not having much luck Googling this question and I thought about posting it on SF, but it actually seems like a development question. If not, please feel free to migrate. So, I have a script that runs via cron every morning at about 3 am. I also run the same scripts manually sometimes. The problem is that every time I run my ...

How to log output in bash and see it in the terminal at the same time?

I have some scripts where I need to see the output and log the result to a file, with the simplest example being: $ update-client > my.log I want to be able to see the output of the command while it's running, but also have it logged to the file. I also log stderr, so I would want to be able to log the error stream while seeing it as ...

Bash/php - any way to implement tab key autocomplete for arguments?

I have a PHP command line script which kicks off a job to a job server, with the job name being an argument. The job names are namespaced, such as Foo:Bar_Baz_JobName. Is there a way I could implement auto-completion, like how typing the first few letters of a filename and pressing tab bash completes the file name for you. I know it can ...

Shell script to find, search and replace array of strings in a file

This is linked to another question/code-golf i asked on http://stackoverflow.com/questions/3171552/code-golf-color-highlighting-of-repeated-text I've got a file 'sample1.txt' with the following content: LoremIpsumissimplydummytextoftheprintingandtypesettingindustry.LoremIpsumhasbeentheindustry'sstandarddummytexteversincethe1500s,whenan...

How do I execute Python/bash code in the current directory as part of a code?

Lets say I am designing a tool foobuzzle (foobuzzle's exact job is to set up SRPM files for cross-compiling a variety of codes into their own compartmentalized prefix directories, but this is not important). I would like foobuzzle to take in an input file (buzzle_input) specified by an (intelligent, code-savvy) client, who will tell foo...

What kind of things can be done using Perl but cannot be done using Bash?

I'm new in using scripting language. I come across 2 scripting languages called Perl and Bash shell script. I would like to know what kind of things can be done using Perl script but cannot be done using Bash shell script? Thanks. ...

Making a command loop in shell with a script

How can one loop a command/program in a Unix shell without writing the loop into a script or other application. For example, I wrote a script that outputs a light sensor value but I'm still testing it right now so I want it run it in a loop by running the executable repeatedly. Maybe I'd also like to just run "ls" or "df" in a loop. I...

Bash Script function verification

I am trying to do validation for every function I call in a script and erroring out the whole script if one function fails. Looking for the best way to do this. I feel I knew a good way to do it at one time, but can't figure it out again. I can brute force it, but it's nasty. This is how I can get it to work correctly copy_files...

How to efficiently convert long int to dotted quad IP in bash

I have a lot of IP addresses in a large mysql DB stored as long int's. I need an efficient/quick way to convert them back to an IP within a BASH shell script ( or have mysql return the results as an IP?? ). Note: specifically don't want to call perl, awk, or other 'language'. ...

Linux shell (bash) on vi's splitview

Hi all, I've been searching with no results for an integration of bash inside vi, as featured in emacs; the problem is: I have vi open with 2 views, one open with :split command, and I want to use bash through the second view, while I'm editing a file in the first; if I do :sh while editing the second view, the whole session pauses and a...

Bash script Find difference between two strings

Given these two strings: "12345" "1245" Where the first one is the complete string and the second has things missing from the first, I want it to return "3". So again with: "The ball is red" "The is red" I want to to return "ball" I've tried diff with: diff <(echo "12345") <(echo "1245") But diff isn't giving the desired outpu...

save and restore shell variables

I have two shell scripts that I'd like to invoke from a C program. I would like shell variables set in the first script to be visible in the second. Here's what it would look like: a.sh: var=blah <save vars> b.sh: <restore vars> echo $var The best I've come up with so far is a variant on "set > /tmp/vars" to save the variables and...

Shell Script For The Web

I want to know if there is any way to use Bash(Shell Script) to make web pages, like Perl, C++ and others through CGI. And if there is any way, where I can find a good free hosting for it? ...

NSTask sending an argument through /bin/sh or /bin/bash problem Cocoa Objective-C

Hello, Basically I've passed a script in the terminal through /bin/bash "[path]" or /bin/sh "[path]", and I've passed commands in a terminal through /bin/bash -c "[command]" or /bin/sh -c "[command]". Both ways work properly. But in my Cocoa App, when I try to do the exact same thing with NSTask (using /bin/bash or /bin/sh), the app see...

What Is the Purpose of the `:' (colon) GNU Bash Builtin?

The question says it: what would be the purpose of a command that does nothing, being little more than a comment leader, but actually a shell built-in in and of itself. It's slower than inserting a comment into your scripts, by about 40% per call, which probably varies greatly on the size of the comment. The only possible reasons I can ...

losing data from bash script in java

I am trying to get bash data into a variable. The problem is that it's so darn random. The command executes every time, I can see that by having an X application start. However my processor may be too fast or slow to issue the echo command and start a buffered read to the input stream. Basically, How can I get this to work? I need...