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

learn more… | top users | synonyms (2)

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
55 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
33 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
38 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
30 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
92 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
66 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
45 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 ...
0
votes
2answers
39 views

How to see what's going in background when we run a .sh file in Linux? [closed]

I know one way i.e. ./filename.sh > log.txt. But that log file is containing the content what appears in console if we run the file using ./filename.sh. Background process is not appearing in log ...
1
vote
1answer
54 views

Check IP is in Range of Whitelist Array

#!/bin/bash MAXCDN_ARRAY="108.161.176.0/20 94.46.144.0/20 146.88.128.0/20 198.232.124.0/22 23.111.8.0/22 217.22.28.0/22 64.125.76.64/27 64.125.76.96/27 64.125.78.96/27 64.125.78.192/27 ...
5
votes
1answer
51 views

Bash script single-quotes parameter with globbing value

I'm trying to write a code search script, with configurable directories and files that are excluded. The main part of this script is the following line: out=$(grep -TInr$C$W --color=always \ ...
0
votes
2answers
62 views

Test bash if conditions in the terminal [closed]

I'm developing a bash script and am spending most of my time on debugging the if condition statements. The reference states: There exists a dedicated command called [ (left bracket special ...
1
vote
1answer
42 views

bash or Ksh quotes and command exec [duplicate]

while creating a script I am facing currently a "strange" issue that so far I am unable to fix. typeset -r SERVICE=\"ldap://localhost:10389\ ldaps://solsrv02.internal.vbox:10689\ ...
0
votes
0answers
24 views

shortening a mv command to loop through multiple files [duplicate]

I used the following command to rename multiple files in different subdirectories. They all initially had a common name sample....., and I wanted to replace the word sample with a specific name for ...
0
votes
0answers
24 views

Remove lines existing in the first file from the second file and remove duplicate lines from a file [duplicate]

First Question Without having to deal with a perl or php script, can I do this efficiently with some common bash programs? With wich command? can you provide a sample? Second Question Can I take a ...
0
votes
1answer
27 views

Moderate users homedirs - removing cleartext passwords [closed]

On one of Linux terminals I administrate, we allow users to write own scripts in bash/perl/python to enhance their administrative tasks. The problem with users is they don't always follow the rules. ...
1
vote
0answers
17 views

Why do I need an `;` or newline in `echo hi| { cat; }`? [duplicate]

In bash and dash the examples echo hi | { cat ; } and echo hi | { cat } produce the intended result hi. However, echo hi | { cat } is a syntax error $ sh -c "echo hi | { cat };" sh: 1: ...
3
votes
2answers
104 views

Writing a script that gives how much lines have “X” and “Y” in it?

I'm doing a course in Linguistic and I would like to use shell scripts to help me doing few repetitive things such as counting who asks questions. Here is part of the file I opened and work with the ...
0
votes
1answer
78 views

Creating Unix script to sleep better

I know that I try to work to late in the night and that at this time I'm absolutely unproductive, I work for 5 minutes then switch to a link seen on youtube, then come back to my work, waste some more ...
-6
votes
3answers
65 views

Bash script won't run

I'm trying to run a bash script named serverloadtest.sh to test a server is performing correctly. However, when I type serverloadtest.sh all I get is 'command not found'. I'm definitely typing the ...
2
votes
0answers
22 views

Producing the next available filename for a pattern (02-output.log etc)

I can use mktemp(1) within a shell script to make a temporary file in a directory with a suitable suffix & prefix. Is there a command that, given a pattern (e.g. NN-output.log) will look for ...
-1
votes
1answer
34 views

Can I use echo to run other commands using this method? [closed]

I'm still learning unix and I need to know if there is a way to perform the following actions. Is there any way I can echo a read variable, and in the process, dissect it letter by letter, and assign ...
0
votes
0answers
19 views

How to test if a command is installed? [duplicate]

For example, if I'm writing a shell script which: depends completely on a specific command being available/installed, or is intended to make use of a specific command if it is available (and ...
3
votes
2answers
62 views

avoid multiple pipes broken due to missing command

In shell scripts I often use multiple pipes like this: cmd1 | cmd2 | cmd3 Now if cmd2 is missing the pipe will result "broken" and cmd3 won't receive any input. As workaround I could test ...
0
votes
0answers
27 views

Perform glob expansion explicitly when `-f` flag is enabled

I've seen in a guides (e.g. this one https://sipb.mit.edu/doc/safe-shell/) recommending using set -f to disable glob expansion (in sh and bash). Is there a way to explicitly perform glob expansion ...
1
vote
1answer
49 views

Display wget transfer in a more compact way (while keeping the error detection functionality)

I know that wget have some options to display or not the progress bars. I would like to display the wget transfer in a more short way, or.. a percent or something dynamic but not taking so much space ...
1
vote
1answer
69 views

regular expression : with a variable

arrFormat=( jpg jpeg bmp tiff png ) varExtension="jpg" for elem in "${arrFormat[@]}" do   echo "${elem}"   # do something on $elem # done #for i in $( find -E . -iregex '.*\.($arrFormat)' ) ; do ...
0
votes
1answer
19 views

How to get desired output from apache access log in Linux

I want the count of error code and corresponding URLs from the apache access log through Bash script. The output should be like that: Count Error-code URLs 24 404 ...
-1
votes
0answers
26 views

Adding on to output file name in a script [duplicate]

I have two files that I'm merging together. Once I run a script on it I would like the file to have an addition tacked on to the name of the file as the output. Input files: window_002_9_R1_.file ...
0
votes
1answer
63 views

How do I accept input string in bash without losing the quotes?

Example, I have this function in my .profile: alias () { command alias "$@" } However, this executes: $ alias test=ls if I run $ alias test="ls" How can I make it accept the string with ...
1
vote
4answers
71 views

How do I echo a string with multiple spaces in bash “untouched”? [duplicate]

I assigned a var like this: MYCUSTOMTAB=' ' But using it in echo both: echo $MYCUSTOMTAB"blah blah" or echo -e $MYCUSTOMTAB"blah blah" just return a single space and the rest of the ...
3
votes
2answers
269 views

How can I do basic calculations in a shell script?

I want to perform some mathematical operations in the shelll. For example: 5+50*3/20 + (19*2)/7 I tried: #!/bin/bash read equ echo "scale=3; $equ" | bc -l Expected output: 17.929 My ...
1
vote
1answer
34 views

how to get or reflect the name of the bash function which is called? [duplicate]

i did not yet found a solution to this. Anyone a hint? i sometimes write bash functions in my shell scripts and i love to have my scripts being verbose, not just for debugging. so sometimes i would ...
-1
votes
2answers
30 views

Search and output string from a file to xml

Received timestamp=1459434658969: ABC: Field id=0 double 11.4 DEF: Field id=1 string >def< GHI: Field id=2 string >g_hi< I would like to read a file that contains input in the above ...
-2
votes
1answer
63 views

When a particular file arrives then execute a procedure using Shell Script [closed]

When a particular file for eg: "abc.csv" file arrives into a directory for eg: "mydir", I need to execute a procedure using shell script. "There was a procedure which will load data from csv to table ...
-1
votes
0answers
65 views

How to write a shell script (.sh file) in CentOS 6 to run commands in different tabs in the same terminal

My commads.sh file so far, #Start the first service cd /home/user/service1 java -jar service1.jar sleep 5 #Start the second service #I need this to start in another tab (if cannot another terminal) ...