Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (2)

3
votes
2answers
46 views

Filtering images according to file name, why?

When filtering the images using the below code, I also need to filter files. For example,IMG_0079.JPG.JPG, when running the code below it's allowing files with additional .JPG to get filtered out, ...
3
votes
4answers
159 views

How to cut everthing until a specific word / after a find in a script

Hello I try to get the output of files from today wich contains ERROR. I use this to find the files I want: find /home/user/logfilesError/ -maxdepth 1 -type f -name "gandalf_*"\ -daystart -mtime ...
3
votes
2answers
82 views

Checking the status of custom services with a script

I have a handful of shell scripts that start WebLogic managed servers. I need to design a master script that does the following: Executes the shell script for a component\managed server Checks to ...
3
votes
2answers
49 views

Have ssh-add be quiet if key already there

I want to put ssh-add /path/to/special_key at the top of a script. This works fine, but it always prompts for the passphrase. This is strange, and a little annoying, as it still asks for the ...
3
votes
3answers
63 views

How to do more than one substring replace at once in bash?

I have a directory contains image files that are to be echoed in bash. While echoing, I want to replace both file name and extension in single line command. Example files: images/file_name_1.jpg ...
3
votes
1answer
63 views

Find and Replace Recursive

I want to modify every file in a directory recursively. I want to replace: <?php with <?php /** * * Copyright (C) MyCompany, Ltd. - All Rights Reserved * Unauthorized copying of ...
3
votes
2answers
56 views

Bash script : help file inside the script or in a different file?

I'm writing a script that has the vocation to be a fully featured program at the end. As far as I know, BASH is enough for his purpose (manage PPA's, kinda like Y-PPA). I would like to know how to ...
3
votes
3answers
284 views

Grep command in shell script

I've been writing a shell script which should make grep command outputs for further use. However when I pass a variable containing ~/.../multiple_dir/* to grep as input I get empty output file. ...
3
votes
1answer
146 views

How do I tell if a program is printing to stderr or stdout in the terminal?

NOTE: a newline appears but od -c doesn't display it. My music player's status command (quodlibet --status | od -c) has three states, and I'm trying to write a conditional based on that output. The ...
3
votes
1answer
137 views

Find directories with a certain name

How can I loop through each directory recursively and whenever it finds a folder called VIDEO_TS, let Genisoimage convert that folder's content to an dvd-video iso image, the name of the iso would be ...
3
votes
1answer
93 views

script to remember dir and always cd to it instead of the root dir

How can write a script to change to a given directory but also remember it so that when you do cd it always changes to that directory ? #!/bin/bash setdir() { cd $1 # remember the directory ...
3
votes
1answer
93 views

Using Bash to write to a device in /sys?

I have one of these: Basically, it's a USB device with three LEDs (red, green, and blue). The Linux kernel has supported this device through the usbled module for quite some time now. However, I ...
3
votes
1answer
149 views

How can I write a sed script to delete numbers from a line?

Sample File a.b.gg3d 0000000001 0000000001 y a.b.112a 0000000000 0000000001 y a.b.gg3s 0000000001 0000000001 y a.b.1111 0000000000 0000000001 m I have a file that includes about three thousand ...
3
votes
2answers
890 views

Optimizing a shell script with long running while loop

I have written a shell script which has to do the following: Capture session commands into one file. Every individual command into separate file. Mail every individual command file content based on ...
3
votes
1answer
9k views

Assigning the output of a SQL query to variable

I am connecting to oracle database and firing a query and assigning the output to variable But when I echo the value of the variable it doesn't get printed correctly. count=`sqlplus -s ...
3
votes
1answer
195 views

How does having /dev/fd make running shell scripts under sudo safe?

At the end of the man page for sudo, there's the following remark: Running shell scripts via sudo can expose the same kernel bugs that make setuid shell scripts unsafe on some operating systems ...
3
votes
3answers
3k views

Concatenate multiple files with same header

I have multiple files with the same header and different vectors below that. I need to concatenate all of them but I want only the header of first file to be concatenated and I don't want other ...
3
votes
2answers
2k views

Is there an easy way to create a FreeBSD rc script?

I have a FreeBSD jail in which I run a server using the command: /usr/sbin/daemon /path/to/script.py At the moment I have to run this command every time I restart the machine and the jail starts. ...
3
votes
1answer
358 views

Extract directory from wget's stdout

I am trying to wget a tarball from github.com and, without creating a temporary file, extract a subdirectory from it: wget -qO- https://github.com/django-nonrel/django-nonrel/tarball/develop | tar ...
3
votes
1answer
326 views

Shell script to execute a command with iteration

This is a script which looks for .tab files in a folder an should imports them with ogr2ogr, but I fail with the correct bracing. for i in $( ls *.tab ) do echo item: $i ogr2ogr -f PostgreSQL ...
3
votes
1answer
203 views

Locking in a shell script

I want to write a long-running shell script so that only one copy could be run at a time. If the script crashes, I want a new invocation of the script not to be stopped by a lock from the crashed ...
3
votes
2answers
338 views

rename randomly files on a USB device

I would like to rename all of my files of my USB device randomly. Indeed, in my car, my tuner has not the random function. I think I can do it with PHP ... but I'm pretty sure it is possible to do ...
3
votes
2answers
684 views

is there any command like “wall” that runs a “command” in all terminals

as you know "wall" command sends a message to all terminals: wall message now my question is this: is there any command that can send a "command" to be run in all terminals? for example sending ...
3
votes
2answers
259 views

What is the bug with this script - using 'select' command to print menu in linux

OS - Linux 64-bit I am trying to implement a simple menu using select command. The script (for testing purposes) is as follows #!/bin/bash echo "*******************" PS3='Select an option and press ...
3
votes
1answer
347 views

Multiple renaming files [duplicate]

Possible Duplicate: How to clean up file extensions? I'd like to rename files with extension .flac.mp3 to extension .mp3. I used the following command $ for i in *; do mv $i `echo $i | sed ...
3
votes
3answers
51 views

How to read a text file line by line which is not constant in shell scripting

I need to read a text file line by line and the lines are not constant it may vary.For example $ cat file1.txt syntax error at or near "?" at character 1 syntax error at or near "[" at character 1 ...
3
votes
2answers
38 views

fdupes - delete files after comparing two directories

I'm currently trying to solve an issue using fdupes. I'd like to compare two folders with each other, and afterwards delete all duplicate files within one of these directories. Example: Files are ...
3
votes
2answers
29 views

Comparing an string by value of a floating number to a number

I wrote the code below: for j in `cat output_10.txt` do dri=`echo $j |cut -d':' -f1` nu=`echo $j |cut -d':' -f2` tot=`echo $j |cut -d':' -f3` fre=`echo $j |cut -d':' -f4` if [ $fre > 2 ] ...
3
votes
1answer
30 views

Why does the read command not take interactive options when run by sh?

I want to download a provisioning script that reads some configuration parameters via read, and execute it: curl http://example.com/provisioning.sh | sh The problem is, that the read command in the ...
3
votes
1answer
16 views

How to execute as the logged-in user in a sudo script (OSX)?

Is there a way to switch contexts like that? The script in my specific case is an installer postinstall script, which requires sudo privileges only for some of the tasks and requires the logged-in ...
3
votes
1answer
310 views

Cron job to delete files older than 3 days

I need to remove files older than 3 days with a cron job in 3 different directories. (these 3 directories are children of a parent directory /a/b/c/1 & /a/b/c/2 & /a/b/c/3) Can this be done ...
3
votes
1answer
36 views

Redistributable completion for my bash scripts

Is there a simple way to embed the completion features inside a script, for bash ? I have a script that I want to redistribute, but I can't ask the people to add something inside their ...
3
votes
1answer
111 views

Automatically detect when a file has reached a size limit

I would like to send an email when a file reach a certain size limit. The only way I thought of doing this is by doing a cronjob which will check the file size and send the email if the file is ...
3
votes
1answer
334 views

chmod + silent mode + how force exit code 0 in spite of error

Is it possible execute chmod and ignore error from command Example ( remark file.txt not exsist to show the example ) When I type chmod 777 file.txt I get error on the output chmod: cannot ...
3
votes
2answers
1k views

How can I print only certain commands from a bash script as they are run?

I have a bash script with various if statements based on command line arguments I pass in when calling it. Having some kind of output as to what commands are being run is helpful to confirm the flow ...
3
votes
2answers
764 views

Insert to oracle table in a loop

Requirement: In one server in a directory multiple files are present. I need to read the file names and populate into a oracle table. I have written the script like this, but its not working: ...
3
votes
1answer
218 views

Machine readable number of updates? Alternative to /usr/lib/update-notifier/apt-check?

/usr/lib/update-notifier/apt-check (from update-notifier-common package) was a fine tool. But it's going to be removed from Debian. /usr/lib/update-notifier/apt-check --human-readable 28 packages can ...
3
votes
1answer
262 views

Array Cartesian product in bash

Is there a way to generate cartesian product of arrays without using loops in bash? One can use curly brackets to do a similar thing: echo {a,b,c}+{1,2,3} a+1 a+2 a+3 b+1 b+2 b+3 c+1 c+2 c+3 but I ...
3
votes
2answers
120 views

Asynchronous RPROMPT?

A friend of mine posted this on StackOverflow, and I thought we might be more likely to get an answer here. His post refers to speed, but we now know that the python script we are using to parse git ...
3
votes
2answers
413 views

Exiting out of an infinite reboot loop in startup (rc.local)

I am creating a startup script (called from rc.local) in Debian Squeeze. The startup script checks for a variable value from a file, decrements the variable and writes it back to the file, then if the ...
3
votes
3answers
728 views

Concatenation of two fields of two files

I have two files : called t1.txt and t2.txt. The contents are : t1.txt a b c t2.txt ab bc cd Now I want to merge these two files line by line into t3.txt so that the t3.txt should look like : ...
3
votes
2answers
100 views

Bash expansion of ${@} as command

I have a parent script while read cmd do nohup ./script ${cmd[@]} &>> log & done < ~/list that executes this child script while true do eval "${CMD[@]}" #${CMD[@]} ...
3
votes
3answers
307 views

Print process ID (PID) of a Matlab instance

To run my Matlab scripts, I've created a shell script to which I give two parameters - the path to the matlab file ($1) and to the log file ($2): nohup time matlab -some_parameters -r "run $1;exit" ...
3
votes
1answer
481 views

Need to improve urlencode function

I need a way to URL encode strings with a shell script on a OpenWRT device running old version of busybox. Right now I ended up with the following code: urlencode() { echo "$@" | awk -v ORS="" '{ ...
3
votes
1answer
466 views

Printing colored text using script

When I type below command in the shell I get the OUTPUT in green color. Command echo "\033[32mCONNECTING TO abpwrk\033[m"; Output(in green color) CONNECTING TO abpwrk But if I use the same ...
3
votes
1answer
612 views

merging files and getting column values based on id field

bash-3.2$ cat sample.log sample.log.1 sample.log.2 ID COL1 COL2 COL4 1 col1 col2 col4 2 c1 c2 c4 3 co1 co2 co4 ID COL3 COL1 1 col3 col1 2 c3 c1 3 co3 co1 ID COL1 COL2 COL3 1 col1 ...
3
votes
2answers
8k views

Wait for process to finish before going to the next line in shell script

I have a script I made to create a backup. I need to make sure the backup is ready before it runs the /home/ftp.sh command. How can I do so? I use CentOS 5.6 #!/bin/bash tar -Pcf ...
3
votes
1answer
1k views

How to use a value returned by a script in grep filter?

I'm on FreeBSD's csh. I want to form a row with domains of one user and then use this row to filter exim maillog to get only mail from/to this user's domains. I wrote a script to form a row from a ...
3
votes
2answers
2k views

Using nohup at /etc/init.d/service

I have been trying to create a daemon using /etc/init.d/myservice and it will call a shell script that contains nohup within the script line. Will it affect it if I could do service stop later?
3
votes
1answer
54 views

two if conditions in for loop bash scripting

I've trying to make two if conditions in for loop. Is it possible this? Now doesn't return anything from second if only two OK from first if. #!/bin/bash servers=("212.39.82.157" "212.39.82.157" ...