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

learn more… | top users | synonyms (2)

1
vote
2answers
200 views

Why does this not work when the load average exceeds 1?

I have been testing this script and its behavior has been odd. The script should generate notifications whenever the load average exceeds a specified limit. Whenever I pass a CPU_LOAD_LMT >=60, no ...
1
vote
1answer
794 views

Error out shell script if plsql program fails

In the shell script, I am calling a PLSQL stored procedure sqlplus -s <<EOF $v_fcp_login set head off feed off serverout on size 1000000 exec ...
0
votes
1answer
353 views

List of special characters in the shell [closed]

I am not sure what they are called, but where could I find a list of wild cards? I see things like: $f %s $1 Is there a definitive list for what each one represents?
4
votes
1answer
742 views

Scoping variables in ksh

In ksh, I have two variables with the same name , one global , other one is local to a function #!/bin/ksh LOG_FILE=lf function exec_script { local LOG_FILE=f print $LOG_FILE } exec_script ...
7
votes
2answers
616 views

What does this ${@:2} mean in shell scripting

I see this in a shell script. variable=${@:2} What is it doing?
1
vote
2answers
6k views

How can i run a part of a script as a different user?

#!/bin/ksh (some code) Log=~/my.log chown USER1 filename su - USER1 -c " date | tee -a ${Log} 2>&1; cd /blah/blah if [ SOMECONDITION ] then sh ./somescript.ksh > logfile fi exit" | tee -a ...
5
votes
1answer
350 views

A program that runs in a shell (e.g. pine) vs. a shell script

Having a bit of trouble finding the answer to my question, perhaps because I may be asking the wrong question. I understand bash scripts. I write them all the time to do little helpful things ...
1
vote
4answers
3k views

How to rotate all images in a directory with imagemagic?

I want to rotate all the images in a directory that match a pattern. So far I have: for file in `ls /tmp/p/DSC*.JPG`; do convert $file -rotate 90 file+'_rotated'.JPG done but that gives no ...
1
vote
3answers
1k views

How to add Multiple Searches in AWK command

Im trying to search for the files Created in June,July and August months. I used this method ls -lrth|awk '/[Jun][Jul][Aug]/ {print}' but it ain't working. Please help me correct the syntax.
0
votes
1answer
547 views

List of 'if' switches anywhere? [closed]

Is there a list of all the if switches for use in bash scripting? Sometimes I see someone using it and I wonder what the switch they're using actually does. Example is the -z in this one. I know how ...
3
votes
3answers
762 views

Rename the last 8 characters in filename

I am receiving video files with different names but the final 8 characters of all are numbers (also different every time). This is the pattern of the file name: custom text 00030402.avi I have to ...
3
votes
1answer
337 views

How do I fix the argument received from getopt?

I have the following commands in my script: set -- `getopt -q agvc:l:t:i: "$@"` ... while [ -n "$1" ] do -i) TIME_GAP_BOOT=$2 shift ;; ... sleep $TIME_GAP_BOOT When invoking the script ...
7
votes
3answers
2k views

which shell will sudo use to execute a shell script without the shebang line

My environment is Ubuntu 12.04 LTS, and the sudo version is 1.8.3p1. First I login as a normal user: $ whoami fin $ cat /etc/passwd | grep -i "root\|fin" root:x:0:0:root:/root:/bin/bash ...
1
vote
1answer
88 views

Scrot command - how to save only thumbnail

I'm using scrot to take screenshots from terminal. However when I want to generate thumbnailed version using parameter -t, I got two files: screenshot.png and screenshot-thumbnail.png. How can I ...
6
votes
3answers
1k views

“Friendly” terminal color names in shell scripts?

I'm aware of libraries in languages such as Ruby and Javascript to make colorizing your terminal scripts easier by using color names like "red". But is there something like this for shell scripts in ...
2
votes
1answer
142 views

Best way to have taskset assign a job to random cores?

I have an application whose license limits it to 4 cores per instance, running on a 16 core box. Several of these instances run in parallel. Instances spin up and down throughout the day. In ...
15
votes
5answers
7k views

Bash script to get ASCII values for alphabet

How do I get the ASCII value of the alphabet? For example, 97 for a?
1
vote
3answers
3k views

bash script check if variable is is [A-Z]

How do I check if a variable is in [A-Z] I want something like this: read var while [ $var in [A-Z] ] do #code here done How to achieve this?
2
votes
1answer
320 views

Cronjob output to log

I'm using a script for testing broadband speed and I would like to set up a cronjob for testing every n minutes and output to a file. The command to launch it from a shell console and append to ...
1
vote
1answer
143 views

Parsing the headers of sequence file

I have a multiple sequence file as >abc|d017961 sequence1...... >cdf|rhtdm9 sequence2...... >ijm|smthr12 sequence3...... >abc|d011wejr sequence4...... >stg|eethwe77 sequence5...... ...
3
votes
3answers
486 views

Command for taking a screenshot to a new file

I want to configure a global hotkey to take a new screenshot and save it, say, somewhere inside my home folder. I can take a screenshot with ImageMagick with this command: import screenshot.jpg ...
1
vote
2answers
107 views

Split out data from a column

So at the moment I have some input email addresses and would like to separate the alias and the domain, then copy them to the end of the line. For example, from a line that has ...
3
votes
3answers
545 views

Convert newline-delimited list with spaces into arguments [duplicate]

I'm trying to write a script that I can run from the context menu in Caja (a clone of Nautilus). Its purpose is to pass the files that are selected in the file manager to a given program (for example, ...
6
votes
3answers
111 views

generate links of pages with incrementing variable

consider the links http://unix.stackexchange.com/questions/tagged/linux?page=2&sort=newest&pagesize=15 ...
2
votes
1answer
106 views

Regular Expressions within a string in AWK using if/then control structure?

PROBLEM I want to specifically use AWK (GAWK, MAWK, whatever) in an AWK script to sum up the values in field 9 for every record that contains "runner__.jpx" (the underscores are placeholders for two ...
3
votes
2answers
4k views

Scripting `rm` and `rm -i`

I want to create a script that whenever there are more than three files being removed, it invokes rm -i by default. I know it will go in initialization files but can't seem to get it working. So far: ...
1
vote
3answers
3k views

Shell scripting to divide numbers inside a file

I have a single column and 12 rows. Each row has numerical values. I want to divide each row values by some constant number (say C) using shell (bash) scripting. How to do this ? Thanks in advance..
1
vote
2answers
2k views

Bash shell scripting basic question regarding the syntax and basename

Consider the script below: myname=`basename $0`; for i in `ls -A` do if [ $i = $myname ] then echo "Sorry i won't rename myself" else newname=`echo $i |tr a-z A-Z` mv $i $newname fi done ...
2
votes
3answers
3k views

Comparing files line by line in awk with delimiter

file1: abc|123|check def|456|map ijk|789|globe lmn|101112|equator file2: abc|123|check def|456|map ijk|789|equator lmn|101112|globe EXPECTED OUTPUT: ijk|789|equator lmn|101112|globe Current ...
1
vote
1answer
3k views

Run .sh file instead of opening it

I am using Zorin OS 7. I want to run a .sh file but I can't seem to be able to—it just opens in a text editor. Also under RMB>open with there is no other option.
0
votes
1answer
616 views

Convert .out file to .pdf using shell script [closed]

I have a .out file I want convert this file to PDF format. Is there any script available for this? File Format :o53770855.out I want to convert this into o53770855.pdf
9
votes
2answers
212 views

How does the syntax “${foo##*.}” work to get file extensions? [duplicate]

Why does this command work in successfully retrieving file extension name? file_ext=${filename##*.}
2
votes
1answer
1k views

download pdf files from using curl

How to download hundereds of .pdf files from http://www.ncbi.nlm.nih.gov/pmc/articles using a loop, for example for the following document ids: PMC3386155 PMC3625956 PMC3477654 PMC3531051 ...
8
votes
3answers
3k views

Use & (ampersand) in single line bash loop

I have been using this command successfully, which changes a variable in a config file then executes a Python script within a loop: for((i=114;i<=255;i+=1)); do echo $i > numbers.txt;python ...
7
votes
3answers
7k views

Rename files in the local folder adding a prefix or suffix

I have many files in a folder and I want to add either prefix or a suffix (not both) to them. I checked here and found out I can use for filename in *.jpg; do mv "$filename" "prefix_$filename"; done; ...
2
votes
3answers
1k views

Cannot add script to init.d

I have installed gerrit on a remote ubuntu server. Now I would like it to automatically start when the server reboots. I am trying to follow this: ...
0
votes
1answer
570 views

How to force google/youtube searches using the bash? [closed]

I'd like to know how to force the bash to do a Google or Youtube searches (in mozilla) of a given phrase. I'm also interested in a scripts that enters a Youtube video and recognizes if there is an ...
2
votes
2answers
179 views

Shell script for auto exceute and shut-down of application based on system time

I need to implement auto start-up and shutdown of a application in Suse Linux based on system time. Eg. Start the application at 10am. Shutdown the application at 5pm. Can this be done using shell ...
1
vote
1answer
389 views

Startscript: using $! to create pidfile - returning wrong pid (off by one) occasionally

We have 3 instances of redis running on a test server. For some reason, our start script which starts redis can write the wrong pid to a file. Here is what it's doing: su redis -c "redis-server ...
5
votes
5answers
339 views

shell script to control the number of processes of an user

I have to launch a total number, NUMTOT of a program (could be any, C, Mathematica, ns-2... mathematical environments). The problem is that the computer where these processes run only admits a ...
5
votes
3answers
2k views

Script to prevent screen blanking using “mouse move” doesn't work

This is my attempt to make a script that will use a "mouse move" to prevent screen blanking while watching videos. I'm hoping to use the value for highest CPU% process in top and if CPU usage exceeds ...
3
votes
4answers
2k views

Wait for multiple files to be finished downloading

I have the following script which checks if there is a file in a folder and if the file is stable (this is for large video file I am receiving). #!/bin/bash cdate1=$(date +%Y%m%d-%T) ...
1
vote
2answers
2k views

What does exec $SHELL -l do?

I have seen this command in a few different shell scripts: exec $SHELL -l ...usually as an alternative to: source ~/.profile What exactly is exec $SHELL -l doing?
2
votes
2answers
306 views

variable declaration does not work

I have the below script in my system: #!/bin/sh LASTFILES=`find /var/log -mtime -1 -iname *.csv` KEYWORDS="MD AG GA" countMD="0" countAG="0" countGA="0" for i in $LASTFILES ; do for a in ...
4
votes
2answers
211 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 ...
7
votes
2answers
573 views

Possible to use brace (permutation) and array expansion simultaneously?

Bash's {} brace expansion syntax allows for creating easy permutations # echo {b,c,d}{a,e,i,o,u} ba be bi bo bu ca ce ci co cu da de di do du However it's not clear to me if/how it's possible to ...
4
votes
3answers
2k views

Summing up an array inside of awk?

I have the following piece of code: sum1= sum2= declare -a a echo $temp | awk '{split($0,a,","); name=a[1] ; for(i=2;i<=4;i++) sum1+=a[i] ; for(i=5;i<=7;i++) sum2+=a[i] }' This code is ...
1
vote
2answers
980 views

squid access.log delete entries older than 6 months

Squid generates a log of the accessed sites by the users. I want to delete the entries in the /var/squid/logs/access.log, which are older than 6 months. I would execute the script each week. I have ...
1
vote
0answers
36 views

(standard_in) 1: parse error [duplicate]

This is my script: #!/bin/sh # 5. Write a Shell Program to Find the Area & Circumference of a Circle echo "Enter the Radius" read radius arear=`echo 3.14 \* $radius \* $radius |bc` circu=`echo 2 ...
5
votes
5answers
767 views

How to concatenate two files on the fly and reference result as new file?

I want to concatenate two files, i.e. staticEntries.dic and dynamicEntries.dic. As the names might show, the content of staticEntries.dic stays the same over time (contains common words), but to the ...