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

learn more… | top users | synonyms (2)

3
votes
2answers
31 views

process Count of each user in ps aux command

How can i create a script to count process run by each user in ps aux. I used this ps aux | awk '{print $1}' | grep root | wc -l but it lists count of root user only . I want to list number of ...
0
votes
3answers
53 views

Store CPU utilization into CSV file

OS: Debian 8 x64 I'd like to log every 5 seconds the CPU percentage into a CSV file in the format below: YYYY-MM-DD HH:MM:SS,CPU% I'm not familiar with how to use the top program to calculate the ...
4
votes
3answers
74 views

How to use call-by-reference on an argument in a bash function

I am trying to pass a "var name" to a function, have the function transform the value the variable with such "var name" contains and then be able to reference the transformed object by its original ...
5
votes
2answers
27k 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
26 views

Notification Listener Behaving Strangely when Backgrounded

I've been struggling to get my IRC-Bouncer/Notification Script working. This is meant to be a script which will automatically login to a remote machine, attach to a screen session (or start one if ...
19
votes
4answers
31k views

Testing if a variable is empty in a shell script

I have seen the following technique used many times on many different shells, to test if a variable is empty: if [ "x$1" = "x" ]; then # Variable is empty fi Are there any advantages on using ...
2
votes
5answers
267 views

Get very next word of a substring in a string

I need to get the next word of a word in a string. I tried to write a script but it's not working. And it's good if you suggest me any other alternatives to achieve this. Script: #!/bin/bash ...
1
vote
2answers
59 views

Need output in a good format using shell script

I have a file, PoolReport.txt. Here is some sample data: Thu, Aug 27, 2015 7:56:29 AM PoolName,Total GB,Used GB ,Available GB ,Percent Full Oracle-RAID10,6432.539,6179.295,253.244,96.063 ...
3
votes
1answer
208 views

prevent a command from sending both stdout & stderr to any terminal or file [duplicate]

I would like to prevent my program from sending stdout and stderr to any terminals, files or devices. For this, I have three command crossing my mind, but I cannot distinguish their differences. Could ...
1
vote
2answers
31 views

Job control over a Bash script

I have a Bash script of a thousand lines each containing an ffmpeg command. I start this with source script and it runs just fine. However, when I try to take control of this script in various ways, ...
0
votes
2answers
32 views

Different behaviour of eval “ command \”$@\“ ”, “$@”, and “$(echo $@)” when used as arguments [duplicate]

I would like to pass multiple arguments to the Tor browser (firefox) programatically through a function arbitrarily entitled tor. This is so as to command tor search terms and voila! My search terms. ...
3
votes
2answers
42 views

How to skip unresponsive server

I wrote a script that runs on multiple servers. Sometimes the script gets hung on one of the servers and I have to hit (control C) to end the process. If not, it gets stuck and keeps trying to ...
2
votes
2answers
31 views

How can I send multiple options to one variable

I am running a loop for an array of variables that generates three more variables. i.e for foo in ${bar[@]}; do bar1=$(echo $foo | awk '{print$1}'); bar2=$(echo $foo | awk '{print$2}'); ...
1
vote
4answers
77 views

Last Working Day of the Month

#!/bin/bash #!/usr/local/bin #!/usr/sbin #!/usr/bin # Script to Check last working Day of the Month echo " Enter Month and Year :" read mon year cal $mon $year| egrep "28|29|30|31"|awk 'BEGIN { ...
0
votes
1answer
32 views

Unable to get actual row counts because of Carriage return values:

I have an input delimiter file.The actual number of records in the file is 4. But due to carriage values now the total count is 8. I just want to do count of rows based on first column values. ...
0
votes
2answers
33 views

Check if process is running Mac OS X then execute code

I am creating a script which clears the cache for Google Chrome. However, I would like to check if Chrome is open and if so not run the code but if it isn't then it will execute the code. I can see ...
1
vote
1answer
24 views

rm all files to the right of “==” printed on the screen

I have a script that prints: dhcp-18-189-47-44:CE06_getting_new_fit myname$ ./find-duplicate-structures.sh custom_structures new_GS_calculation/selected/POSCAR_00* ...
0
votes
1answer
21 views

Manage multiple servers

I wrote a simple script that I want to run on several hosts. (I.e., I want to run one instance of the script, but have it operate on several hosts.) The script works, but only for the first host. When ...
0
votes
0answers
27 views

How do I send a variable through SSH so it can be used across servers? C Shell

EDIT: Would this be possible in bash? Note: I have to use C shell. (.csh) I have something very similar to the following code: set var = "string" ssh -X server "$var" << END * I ...
-3
votes
3answers
46 views

Shell Programming Quesiton with Loops Until and While

I need a solution for the below Write a Shell program to print the numbers in the following format: Use While or Until loop for the following program 1 2 3 4 2 3 4 5 3 4 5 6 4 5 6 7 5 6 7 8 6 7 8 9 ...
0
votes
1answer
23 views

How to run bunch of hierarchical dummy shell processes (process of another process, etc.)?

I would like to run multiple processes where each process is running another one, so it will create a long process branch. I've tried: $ bash -c '(bash -c "sleep 20"); sleep 20' & $ pstree ...
0
votes
2answers
32 views

Insert text to file using bash scripts (NOT appending)

I want to add text to a file using shell-scripts. The solution I know is if you want to insert your text into a newline (appending): echo "mytext" >> myfile.txt what I want to have a ...
0
votes
1answer
2k views

LFTP mirror upload only non existing files to remote directory

Every 5 minutes some new files are downloaded via lftp to a local directory. I need to upload to another ftp only the non existing files. My script so far is: #! /bin/bash today=$(date +%Y%m%d) ...
1
vote
1answer
852 views

Run a command under sudo over SSH

I am accessing remote machine in Linux using Bash scripting.My code is as follows #!/bin/bash ssh -i manu_bp.pem ubuntu@54.68.67.68 <<EOF sudo -s cat ...
14
votes
11answers
47k views

Show sum of file sizes in directory listing

The Windows dir directory listing command has a line at the end showing the total amount of space taken up by the files listed. For example, dir *.exe shows all the .exe files in the current ...
2
votes
2answers
34 views

automating CentOS 7 configuration using shell scripts

I notice I spend a lot of time using tutorials to manually configure a CentOS 7 server. How can I convert the manual steps from a tutorial into an automated shell script that can be used to configure ...
0
votes
1answer
35 views

How to add a folder to a remote hosts PATH using a shell script?

I'd like to automate the process of syncing a local ~/bin folder to a remote host, and adding that folder to my remote shell's path. I've got the syncing part done, but am not sure how to automate ...
1
vote
3answers
476 views

rename files with rename command

Please advice what is wrong with the following command find /tmp/dir -name "* *" -type f | rename 's/*/fixed_/g' remark - I prefer to do that with one command not loop syntax What I want is to ...
3
votes
1answer
148 views

Exit bash when find gets to a folder with permission denied

I'm trying to write my second Bash script. Where i go through folders recursively and make a list of and count files and folders. In a way it works but if "find" gets to a directory where it has ...
31
votes
4answers
2k views

Should I care about unnecessary cats?

A lot of command-line utilities can take their input either from a pipe or as a filename argument. For long shell scripts, I find starting the chain off with a cat makes it more readable, especially ...
0
votes
2answers
31 views

It is possible to list all files that have at least 3 letters on its name?

I have to find all files that have a minimum of 3 letters, starting with the letter "l". I'm using this, but it also gives me the files with less than 3 letters. ls | grep "^l" Is it possible ...
-1
votes
1answer
47 views

Unix script meaning required

I am trying to run a script in unix. It's a simulation that I need to run for two different months. For that the following portion of the script is vital. Can anyone please tell what it means? set ...
4
votes
3answers
569 views

Loop ignores change of variable from a subshell in the background

I wrote a script that contains an until loop. This loop should run till a boolean variable is set to true from outside the loop. Unfortunately the loop ignores that the variable has been set to true ...
0
votes
2answers
23 views

Replace a second field output with sed or awk

I have a below content in a file where i need to search the pattern "application:" , where "application:" should be there but the next field to it should be changed to "RMAN" , I am trying to do with ...
1
vote
1answer
42 views

How to print the line numbers with corresponding line that matches a pattern using shell command? [duplicate]

File, .false alarm is bla no. 11 .no alarm generated is bla .application will be killed is bla wall command .doc file is document file with .doc extension .no authority for this selection bla Now ...
1
vote
1answer
36 views

Batch renaming of files with ascending number

I have a batch of files: $ ls Li1Fe1O2_11 Li1Fe2O3_8 Li1Fe3O4_2 Li1Fe3O4_5 Li2Fe1O3_16 Li2Fe2O4_12 Li3Fe1O4_19 Li3Fe1O4_22 Li1Fe1O2_14 Li1Fe2O3_9 Li1Fe3O4_3 Li1Fe3O4_6 Li2Fe1O3_17 Li2Fe2O4_13 ...
1
vote
1answer
36 views

Identifying duplicate fields and print both with awk

I have a file with multiple columns and want to identify those where specific column values (cols 3-6) have been duplicated. The following code finds the duplicates but I want to display both ...
0
votes
1answer
36 views

Scripts in rc.local (start at boot), doesnot start

In my Debian /etc/rc.local, I've put 2 scripts (one for Wifi AP, the other for VPN client-connection): sh /bootscripts/vpn.sh & sh /bootscripts/wifiap.sh & #test: date >> ...
4
votes
3answers
559 views

Find files in directory with paired names

I'm running tests of a variable-size-and-contents test set. Data files are added and removed frequently. I'm looking for an automated way of gathering a file list. All files are in subdirectories of ...
0
votes
1answer
55 views

How to grep the following lines from a file?

I have a file which has the names of many files in a directory in the following format: A20150824.0950-0955_jambala_CcnActiveSessionCounterJob A20150824.0945-0950_jambala_CcnActiveSessionCounterJob ...
0
votes
1answer
49 views

sed in while read loop doesn't complete commands

I have a test file called testPage with the following text: || '''Title1''' || '''Title2''' || '''Title3''' || || Cell11 || Cell12 || Cell13 || || Cell21 || Cell22 || || Cell31 || Cell32 || || Cell41 ...
0
votes
3answers
42 views

combining n number of files with cat command

I have n number of files, I have stored filenames in a list and I want to combine them. I am doing this manually, i.e. If n=3 cat ${filename[1]} ${filename[2]} ${filename[3]} > newfile If the ...
0
votes
2answers
29 views

Bash script error [on hold]

I created this bash script based on answers I found here: If [[ $(autorep -J jobname | cut -c108-110 | sed -n '/ST/!'p | sed '/^$/d' | sed -n '/_/!'p) == *ST* ]]; then echo "Status is Started" fi ...
1
vote
1answer
82 views

'while read line do' cause: “syntax error near unexpected token `done'” in Linux bash script

I have a shell script which is running fine on Solaris platform but not working on Linux platform. The Failing code snippet is as following: [...] while read line do insert_into_table="insert into ...
0
votes
2answers
50 views

Bash script that removes part of a filename in every file under a directory

I have several files under a directory whose names are of the form *.foo.bar. I would like to write a bash script to rename each of these files by removing the .foo part. For example, suppose that ...
1
vote
2answers
49 views

Escaping a linux command

I'm trying to run a command from a script I wrote that basically replaces a string in file vzctl exec VZID sed -i 's/\/>/address="$IP\/255.255.255.0"\/\>/' "file.xml" The problem is the ...
0
votes
1answer
22 views

Script to remove certain span elements from an HTML file

I want to write a script that completely removes every instance of a particular span class from a given HTML file. For example, if my undesired span class is "foo" then running my script on the file ...
-1
votes
0answers
25 views

Request a second available IP from the DHCP server? [on hold]

I have 3 servers A, B and C that already have IP addresses assigned by the DHCP server. I wanted to request a fourth IP from the DHCP server that I can use as a floating IP between my service. Is ...
3
votes
2answers
441 views

Need shell script to transform a CSV into Apache httpd format

Need some pointing in right direction on script to fetch and regex or sed. Site24x7 provides a URL with a CSV list of their source IP's used for monitoring. (they also provide other formats, CSV ...
0
votes
1answer
26 views

DNS Query Script

I am trying to get all the A records for some domains. The best way I have found is to use https://www.whatsmydns.net and the nexcess tool. The issue is that it is very slow to copy paste them and ...