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

learn more… | top users | synonyms (2)

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
340 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
307 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
212 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
577 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
985 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
768 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 ...
1
vote
3answers
21k views

Returning a value from a bash function

I have a function which returns 1 if the number is a valid ten digit number: valNum() { flag=1 if [[ $1 != [1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] ]]; then echo "Invalid ...
2
votes
1answer
806 views

Send attachment to gmail id from shell script

I have a shell script that generates reports. Using crontab i run the scrip everyday at 1000 hrs. I want to mail that report to my gmail id as an attachment. I have tried using mutt but it doesnt ...
1
vote
2answers
657 views

Improve sed command to replace first instance of character and all following characters?

Input: <e1 name="file1" id="id1" anotherId="id2"> Desired output: file1 I can get what I need with this: echo '<e1 name="file1" id="id1" anotherId="id2">' | sed ...
7
votes
5answers
5k views

Compare two files with first column and remove duplicate row from 2nd file in shell script

I will ask my question with an example. I have 2 files: File #1: 118D FC300_R5_TP FX.B 32775 2112 6 2038 6 2112 0 118E FC300_R5_TP FX.B 32775 2136 7 ...
2
votes
4answers
2k views

Shell script to validate mount point status in the linux server

I'm in need of a script which should work as below. A script where it would validate if that specific mountpoint is currently mounted on the server. It would search for mountpoint name in /etc/fstab ...
1
vote
2answers
183 views

How to write script that watching directory for lessc command?

I use lesscss extensively. I want to write bash script that watching my target directory, and then when .less file was modified and saved, command: lessc should be executed automatically. For ...
0
votes
3answers
205 views

Run two commands on same argument

I was wanting to maybe alias a command such that the command ran as per usual but also did something else on the argument/s before it was executed. An example might be: alias ls="echo displaying ...
1
vote
1answer
160 views

why csv is consuming more file size in my unix script?

I'm using this unix script which it is fetching records in the form of csv. I have a SQL query used for this purpose. It contains below information SET PAGESIZE 5000 SET COLSEP "," SET LINESIZE 2000 ...
4
votes
4answers
950 views

Joining two files with unique identifier

I have two files with approximately 12900 and 4400 entries respectively, that I want to join. The files contain location information for all landbased weather observing stations around the globe. The ...
2
votes
4answers
4k views

How can I either encrypt or render my shell script unreadable?

How can I encrypt or scramble my shell script so that it's unreadable to the naked eye? Either method would be acceptable, please provide specific steps.
3
votes
1answer
188 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 ...
2
votes
2answers
733 views

How can I add an array of arguments inside my rsync call inside a script?

I want to copy a folder to another location, while excluding some specific files Here is my current script: #!/bin/bash if [ -n "$2" ] then source=$(readlink -f $1) destination=$(readlink ...
2
votes
1answer
5k views

bash: integer expression expected

I have a file out.csv I have to check if the name inputed by user exists in the file(comma separated) or not. I am taking name using read but while checking for equality I am getting error ...
2
votes
2answers
119 views

selecting specific string in a field

I have this file: N104 F1810 N104 F3810 N104 F810 N104 F305 and a script to grep an input. Script: enter input read input cat file | grep $input when I input “810”, I get the ...
2
votes
4answers
2k views

SSH exits after quit case in bash script

So I have the following standard script: #!/bin/bash PS3='Please enter your choice: ' options=("option 1" "Option 2" "Option 3" "Quit") select opt in "${options[@]}" do ...
2
votes
2answers
3k views

For loop for renaming files with prompt for each filename

I have to convert multiple video files in a folder. I have to rename each one of them but I need the script to prompt me to write a custom name for each filename. Here is what I've got so far: First ...
1
vote
2answers
415 views

Shell: Break both if and for loop at once

Shell: Break both if and for loop at once. My script: ip to name resolve code IP=192.168.27.191 hostNameChecker() { if [ `getent hosts $1 | wc -l` -ne 0 ];then HOST_NAME=`hostname` ...
2
votes
0answers
1k views

Script stops command in it with exit 0

When I write a bash script similar to this on RHEL 6, if [ "$2" = "" ] ; then echo vip.start: ERROR: no NIC specified echo vip.start: Need IP and base interface name exit 1 fi case "$1" ...
2
votes
3answers
11k views

Loop over a file and read values from two columns into variables

I have a file (data.dat) which contains 3 columns. I want to read in two of them with the shell script and fill the contents into a template file. The file looks like this: 12 180 2390 14 177 2210 16 ...
2
votes
2answers
2k views

what is >> symbol and >& in unix/Linux? [duplicate]

I have a CRONTAB entry as below. Can someone tell me what the below statement is exactly doing? 1 0 * * * /vol01/sites/provisioning/MNMS/45627/45627.sh1 >> ...
0
votes
1answer
326 views

Change date after SSH login in shell script

I have to change the date after an SSH login into machine, but I am not able to change it. Here is the script I have written: #!/bin/bash ENVIRONMENT_LIST=environment_ip_list USERNAME=root declare ...
3
votes
2answers
2k views

How to safely reverse dns lookup on ip in a shell script

I'm trying to find out how to take in a hostname and pop out an ip address (reverse dns lookup). I came up with this but I'm not too sure it's safe across different linux distros: nslookup $ip|grep ...
1
vote
1answer
995 views

How to figure out where a link gets redirected

I currently working on a script that updates a file. The file has several versions. The important ones have static links. These get redirected to the actual file which then gets downloaded using wget. ...
1
vote
2answers
2k views

To configure script to send email only when diff command gives a difference

I'm new to the world of scripting and and currently using a script to perform a health check on the san devices that I manage. The script is simple and redirects output of commands to a current file ...
1
vote
3answers
543 views

Which cmd is the best for determining the OS' word size (32/64)-bit? [duplicate]

I need to find my OS (not hardware) is 32-bit / 64-bit. Which command is best? uname -p uname -i uname -m arch All the above commands returns the same answer: On 32 bit systems: i686/i386 On ...
13
votes
1answer
1k views

How does a fork bomb work?

WARNING DO NOT ATTEMPT TO RUN THIS ON A PRODUCTION MACHINE In reading the Wikipedia page on the topic I generally follow what's going on with the following code: :(){ :|:& };: excerpt of ...
2
votes
1answer
176 views

Linux: I need to create installer for my own application using shell script

Linux: I need to create installer for my own application using shell script. I need to distribute my application as installer without GUI and also not as rpm's or any other packages. My application ...
13
votes
1answer
10k views

Empty the contents of a file

I am aware of three methods to delete all entries from a file. They are >filename touch filename filename < /dev/null Of these three I abuse >filename the most as that requires the ...
5
votes
3answers
1k views

Cron to not run on specific day but all other days

I have a cron setup to execute a bash script daily at 10pm. I have another cron setup to run monthly on the 1st of the month. Both crons launch a bash script, and the only different in the bash script ...
1
vote
4answers
4k views

Match multiple regular expressions from a single file using awk

I'm trying to parse a HTML file using shell scripting. There are 4 different regular expressions that i need to catch: name= , age= , classs= , marks=. Using grep "name=\|age=\|class=\|marks=" ...
2
votes
4answers
3k views

FTP bulk download and rename

First of all: Why I'm trying this? Because we need to download some files AND rename to shorten ones with date "stamps". The remote files have really huge filenames and it's not an option to ...
0
votes
2answers
621 views

Unix: How to Test Ip Address is resolved to name

Unix: How to Test ip Address is resolved to name. I need to check whether ip address can be resolved to name using DNS entry via shell script. Code: DNS_Lookup() { LOOKUP=$(nslookup $1) ...
2
votes
3answers
3k views

How is it possible to sort ps command's CPU field?

I'm trying to make a small command that will find the processes that use the most CPU power. Firstly, I use ps aux > file.txt and then cut -c 16-20 file.txt | sort -n | tail -5. The result I get ...
1
vote
1answer
449 views

Execute command supplied by function parameters

I'm trying to create a function method in a bash script that executes a command which is supplied to the method by the paramters. Meaning somethings like this: special_execute() { # Some code ...
3
votes
5answers
257 views

Comparing Indices of two strings

I have two double quoted strings of same length, that look like this: "$con" - (consists of spaces and *'s): * ****** *** ** * ** and ...
2
votes
1answer
13k views

Concatenating two variables with an underscore [duplicate]

Alright. I need to concatenate two variables to create a filename that has an underscore. Lets call my variables $FILENAME and $EXTENSION where filename is read from a file. FILENAME=Hello ...