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

learn more… | top users | synonyms (2)

3
votes
1answer
35 views

Standard/canonical way to test whether foregoing pipeline produced output?

The situation I have in mind has the following structure: % some_command | [PRODUCED OUTPUT] || echo 'no output' >&2 Here [PRODUCED OUTPUT] stands for some as-yet-unspecified testing ...
0
votes
2answers
42 views

How to take the values from two columns in a txt file and match them to values in another

I have two text files formatted as follows: e.g. File1: 900 480 10060.62 2740 -266864.19 3843493.50 2740.00 2740 176.07 900 479 10046.50 2741 ...
0
votes
1answer
50 views

shell script works fine when executed in terminal, but errors out when ran as concurrent program

I'm trying to add the below string manipulation commands in my existing shell script. #!/bin/ksh y=${#text} echo "Length of text: $y" echo "Last _ is in column $((${#text} - ${#end}))" echo "Our ...
0
votes
1answer
60 views

How do I start a background process from a shell script and log the output of the process?

I have a shell script similar to the following: #!/bin/bash # Here is where I set a bunch of environment variables that are # used by the process invoked below... # Now I want to invoke the process ...
0
votes
2answers
43 views

Remove string with > and forward-slash from xml code

I want to remove two strings globally from some xml code. They are: </sellingStatus> and <sellingStatus> I have tried the following unsuccessfully: sed -i 'sed -i ...
3
votes
2answers
129 views

How to extract strings from one file into multiple files

I have a file, xxx.lst with the following data: aaa 111 bbb 222 ccc 333 I need to make 3 files called 111.lst, 222.lst and 333.lst respectively with aaa in 111.lst bbb in 222.lst and ccc in ...
1
vote
0answers
24 views

pmap hangs on OOM process

I did attempt a search, but there doesn't appear to be much out there on pmap so here goes. I have a script that works with WebLogic instances to gather data on them which we can send to our Devs for ...
1
vote
2answers
41 views

Can someone clarify for me about the global variable in this shell script?

Here's the code. #!/bin/bash var_change() { local var1='local 1' echo Inside function: var1 is $var1 : var2 is $var2 var1='changed again' var2='2 changed again' } var1='global 1' var2='global ...
2
votes
2answers
41 views

Efficient Use of dd (buffer many blocks, process one at a time)

Given a file, I need to search for the number of blocks that matches an input block $templateBlock of certain size $blockSize. What is an efficient way to use dd to accomplish this task? The ...
0
votes
2answers
36 views

Command to merge all terminal windows?

Is there a terminal command that merges all open terminal windows into one window with tabs? Been searching all over the place, but have yet to find any solutions.
-1
votes
1answer
31 views

negation equivalence

I have this exercise: Write a script, which uses if-then-else-fi and accept sequence of parameters -a and -b with values "true" and "false", while for every pair writes negation of expression -a ...
0
votes
1answer
19 views

How do you handle multiple validation rules on varied user input?

I'm using a Bash script to prompt users for several variables before continuing. If I want to create static validation rules and execute them on user inputs in an "a la carte" fashion, how would I go ...
0
votes
0answers
41 views

Testing Remote SMTP Server Port

I am currently working in a lab environment to test a script for my production environment. My environment has several remote firewalls, all of which have an external mail Virtual IP (VIP). Our ...
0
votes
1answer
38 views

How to execute a script on SSH Login or device bootup/shutdown? [duplicate]

I have a raspberry pi, which is online and connectable by SSH. What I want to do is create hooks for the following states: When the device starts Before the device shuts down When an SSH login ...
15
votes
3answers
2k views

What does ${1:0:2} mean in this context?

I am looking into the code displayed below and it checks the input if the row/column arguments start with either -r or -c. What does ${1:0:2} mean in this context? rowArgName="-r" colArgName="-c" ...
0
votes
1answer
16 views

Bash redirection in sub (called / spawned) scripts

I'm using apcupsd to respond to events on an APC UPS. The daemon effects responses by chaining BASH scripts. First it calls apccontrol (appending 4 arguments) which in turn calls a script specific to ...
0
votes
2answers
52 views

get day from date with append 0 in 1 to 9 digit

i am using awk command to get creation date of file and from that i m fetching day,month and year but for 1-9 digit i am getting output like 2016041 but i want output 20160401. D=$(ls -ltr $line | ...
0
votes
1answer
35 views

Bash script to find files with a string in the title and print them and ask to delete them

I wish I could make that title more specific. So I need to make a bash script that takes two arguments, one is the string to search for in the filenames and the next one is the file path to search in. ...
-2
votes
1answer
64 views

quick and easy way to comment out multi lined print statements

Is there a quick and easy way to comment out multi lined print statements? something like this? printf("3387 strings_line_tokens[lower_bound_of_big_boy_counter] %s \n", ...
0
votes
0answers
8 views

How to see the remained time for forced termination of execution for pbs job?

Suppose I have some interacting pbs job. How to see the remained time for forced termination of execution for this job?
1
vote
3answers
73 views

Using grep in conditional statement in bash

I'm still very new to scripting in bash, and just trying a few what I thought would be basic things. I want to run DDNS that updates from the my server running Ubuntu 14.04. Borrowing some code from ...
3
votes
1answer
31 views

Why does this fish script does not run from a launcher?

I've written the following script, intended to start a daemon and display a Zenity window, then stop the daemon when the window is closed: #!/usr/bin/fish if not ps aux | grep [s]erviio > ...
0
votes
1answer
26 views

setenv within script does not override value set at prompt

trying to do setenv OMP_NUM_THREADS 8 if at the prompt in a shell I do setenv OMP_NUM_THREADS 4 that is successful. And my program runs on 4 cores if i launch it. But I have a file called runme ...
2
votes
2answers
60 views

find and replace double bracket values

I have a requirement to replace the [[KEY]] in double brackets in one of the html file with VALUE. Key values are available in different files. After replacement, I need to put output in separate ...
0
votes
1answer
25 views

Determining Domain Base Name from Nslookup Results [closed]

I am trying to search all IP addresses that connected to my server and want to find abusive servers from nslookup results. nslookup 31.204.150.10 | grep "in-addr" Some example results: ...
-1
votes
3answers
42 views

In a bash shell script , how to write a loop that goes trough three values [duplicate]

I'm trying to write a shell script using bash for the following problem: Write a loop to go through three values (A B C) and displays each of these values to the screen (hint use a ‘for’ loop). ...
0
votes
2answers
44 views

Saving Output In a Variable and Re-using it

page=`grep $x /var/www/vhosts/example.com/statistics/logs/access_log | awk '{print $7}'| sort |uniq -c |sort -nr` times=`$page | wc -l` I am trying to save output of grep in a variable as page. But ...
1
vote
2answers
77 views

Why is this script looping on the first line of the txt file?

#!/bin/bash usernameFile="/home/netadmin/username_list.txt" logFile="/var/log/netvpn-mag-archive/netvpn-mag-20160" while read -r line < $usernameFile; do if [[ "$line" != " " ]]; then ...
1
vote
3answers
90 views

How to list all weekends for the next 6 months?

$ SAT=$(date -dsaturday +%Y-%m-%d) $ SUN=$(date -dsunday +%Y-%m-%d) $ $ echo $SAT 2016-04-09 $ echo $SUN 2016-04-10 $ I know how can I list the next dates for Saturday and Sunday. How can I list ...
0
votes
3answers
32 views

Accessing Secondary Variables

for x in `cat /var/www/vhosts/example.com/statistics/logs/access_log.processed | awk '{print $1}' | sort | uniq -c | sort -nr | awk {'if ($1 > 2000) print $2'}`; do #Works printf ...
2
votes
1answer
22 views

Connect via telnet and doing certain operations

I'm trying to code a script where I can connect via telnet to another server and execute certain operations, but I'm having problems with the result of this process. The objective is to connect to a ...
2
votes
0answers
56 views

bash script autobeautifiying using declare -f

I am trying to "beautify" scripts automatically by using declare -f function In a nutshell: Given a bash script foo , you can apparently "automagically" indent it by doing, in bash: MAGIC () { ...
0
votes
1answer
36 views

How to run menu options automatically in unix script

I am new to UNIX and tried to create automation script as per my requirement but stuck up in the middle.please help on this. Requirement: directory /usr/ab/bc contains two menus as test ...
1
vote
1answer
30 views

Substitute with `…` multiline output of find command [duplicate]

I need to substitute output of find command to another command to process every found file, e.g.: mdls `find ~/target_dir/ -iname '*some*' -depth 1` (mdls is a command in OS X which get metadata ...
0
votes
2answers
40 views

Remove string with spaces and quotes from xml file

I would like to remove the string currencyId="GBP" from an xml file. Please note there is a single space before the first letter c. I am having trouble parsing the data and removing this string ...
1
vote
1answer
37 views

Bash script to summarize “ last -a ”

I would like to make a shell script such that it runs the " last -a " command and summarizes it's data in the form : userID : number of login sessions Host or ip1 - number of ...
1
vote
1answer
103 views

Running a part of shell script as a different user

This question has been asked before, but I can't seem to get it work. One of the solutions I tried is using here-document. I used the following code: #!/bin/bash su - mv2 <<EOSU ...
2
votes
2answers
79 views

Sorting one file line by line based on another file

I'm trying to sort the rows of a text file based on an 'index' in another file, such that the text file is arranged, row by row, in the same order as the index file. The following code achieves what ...
0
votes
1answer
32 views

How to insert a string before a matched string

How can I insert a string before a matched string. Suppose I want to insert a string a before "if (PROTOCOL == "https://")" string. Please tell me how can I do this?? or How to search and replace ...
0
votes
1answer
33 views

How to Extract the current date Date Log from catalina.out file

I have 2.5GB catalina.out file. I need to extract the current date's logs from this file. Please help me to achieve this. Please see below my log file format: 2016-02-15 19:49:45 INFO ...
0
votes
0answers
33 views

Shell script to check the ASM diskgroup space in oracle and send a mail

I am trying to write a shell script to monitor ASM instance in ORACLE and mail the respective people in mail list. I have written the following script. #/bin/sh #set -x USER=xxx PASS=yyy ...
1
vote
2answers
93 views

BASH- Find owner of a file

Im looking for a way inside a bash script to return the owner of a file. I'm guessing that this is possible using "gawk" but I've honestly got no clue and there doesn't seem to be a comprehensible ...
12
votes
1answer
137 views

POSIX equivalent for GNU timeout?

The GNU coreutils timeout command is extremely handy for certain scripting situations, allowing for using the output of a command if it is quick to run, and skipping it if it would take too long. How ...
3
votes
1answer
54 views

A common way of combining two files in Solaris and Linux

I am trying to write a script that would combine two files into one and should work in both Solaris 5.10 and a Linux box. File1: dit710 dit710 dit720 dit720 File2: FacA D0000000000000001 FacA ...
1
vote
1answer
67 views

How to move a file if the folder name contains the filename

I am very new to shell scripting in linux. I have a bunch of files in source directory. I have to move the files to the target directory where the folder should contains the file name(not exact ...
0
votes
1answer
46 views

mv misbehaves in shell script [closed]

I have the following folder structure: /backup /backup/copy.sh /backup/archive/ /backup/20160405_logs/ /backup/20160405_logs/sql.log /backup/20160405_logs/bak.log I want to move the folder ...
1
vote
2answers
28 views

I want to catch the STDERR and STDOUT of Background running script

I have to run a script background and also i have to catch the STDERR and STDOUT . i'm using the below line . test.sh & >> log_file 2>&1 But un fortunately nothing is getting ...
-3
votes
0answers
39 views

Vncpasswd script for ubuntu 14 server

I have all other issues resolved one last thing is ,i want vncpasswd as automated . These commands are working perfectly when i copy paste them in terminal but these aint working in script File. I ...
0
votes
0answers
13 views

how do you make a list/file for pacman to install from

I am trying to move from one arch install a (partitioned one) to another (a less-partitioned one) on my computer and I want a similar set up. So I was wondering if there was a simple way to get pacman ...
0
votes
0answers
23 views

Script stops working after httpd stop

Here is my script file updateslave.sh code as .... cd /home/smart echo "Removing Old Update Files " rm html* -Rf service mysqld stop service httpd stop mydate=`date +%F` masterIP=`cat ...