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

learn more… | top users | synonyms (2)

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
41 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
55 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
52 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
64 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
44 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
67 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
63 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
28 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
51 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
64 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
74 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
270 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
31 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
64 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
71 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) ...
0
votes
5answers
117 views

How do I display all the characters between two specific strings?

I want to display all the characters in a file between strings "xxx" and "yyy" (the quotes are not part of the delimiters). How can I do that ? For example, if i have input "Hello world xxx this is a ...
3
votes
2answers
46 views

Iterating over glob patterns, not the files in them

I would like to perform the same aggregation operations on each of several bunches of files where each bunch is matched by one glob pattern. What I would not like to do is pipe each file name into the ...
1
vote
2answers
48 views

How to sum the output of two commands and save it to a file?

I have two kfsql commands that get total count of users. I need these two command outputs to be added up and printed to a file.txt I tried: var1= getdatabase1 var2= getdatabase2 echo "$var1" echo ...
2
votes
3answers
92 views

How to sort files in Bash with ddmmyy timestamps in name

I have a series of files with names of the form "foo.date.bar" where "date" is a six digit field such as 310715. So for example foo.310715.bar foo.260815.bar foo.110815.bar foo.040815.bar I would ...
3
votes
2answers
46 views

detect if PDF file is made from images

I'm trying to pre-process a huge amount of PDF files, many of them not actually text but images in order to move them to a proper location to OCR processing. The problem is I've tried to detect if ...
0
votes
1answer
34 views

Shell script that outputs chmod command for all files

On my EC2 Linux server, I blindly ran chmod 777 at directory that it turns out I should not have. There are hundreds of files in there, and I'm not sure which ones need to go back to their original ...
0
votes
2answers
48 views

How to get absolute path of current shell in a sourced script? [duplicate]

Suppose one executes either . some_script or source some_script How can some_script determine the absolute path of the current shell (i.e. the one that is executing the . or source command)? ...
0
votes
2answers
23 views

Shell script - child - background process

I have the following situation : As root Script_A.sh is run on the server and sleeps until triggered. When triggered, it calls Script_B.sh, which loops on the server to determine which actions it ...
0
votes
4answers
199 views

Obtain script current directory (so that I can do include files without relative paths and run the script from everywhere)

I have the following problem, my shell script contain something like: mydir='' # config load source $mydir/config.sh .... execute various commands My script is placed in my user dir.. let's say ...
1
vote
3answers
43 views

Unable to source file

I have a scenario where a tomcat user-defined configuration is stored in a file called tomcat.env. In catalina.sh we are sourcing the values as below: . "$CATALINA_BASE/bin/setenv.sh" But as the ...
1
vote
2answers
72 views

rename multiple files in multiple directories using Bash scripting

I want to rename multiple files in multiple directories using Bash scripting. I have 772 such directories i.e from Nishi_001 to Nishi_772. Each directory has different number of files in it but in ...
0
votes
1answer
40 views

Why is this script not copying the files inside my source directory?

I am running a script with two arguments. myshell.sh source destination So I want to copy all the files (not including subdirectories) inside the source directory and copy them to the destination ...
0
votes
0answers
38 views

I have a command not found error in my shell script when I run the code

when I run the code below I get the error message "line 19: checkUser: command not found". I have tried using shellcheck but I still couldn't fix the issue with the code. #!/usr/bin/env bash ...
1
vote
1answer
45 views

bash scripting - wget or curl file with action based on the status 200 or not

I would like to write a script where I try to download a file with wget (or curl if is really not something that can be done with wget) and do 2 actions if the file exists and it's downloaded ...
2
votes
2answers
51 views

Updating shell functions and aliases through environment variables

Say we define the following shell function and alias in .zshenv: export VARIABLE_A='original' function my_function() { print $VARIABLE_A } export VARIABLE_B='original' alias my_alias="print ...
1
vote
1answer
29 views

curl load IPs from Text file

I have a list of IPs and want to run a specific curl command on each of them. The command is: curl --user test:test http://192.168.1.1/security/pkm.html | egrep '@company|config.pkm.password' ...
1
vote
1answer
23 views

cron job for pure-quotacheck with pure-pw list [closed]

I want to automate the process of quota checks for a pure-ftp server. I've read the docs, so I can do that with pure-quotacheck -d /path2/home -u user The simplest method that I could think of is to ...
0
votes
2answers
46 views

use of if else in linux to find whether the folder exists or not

I have the following bash script: if [ -d "/$home/DB_handouts"] then echo "Directory DB_handouts found" else mkdir /$home/DB_handouts chmod 777 /$home/DB_handouts fi Running the above code ...
0
votes
1answer
52 views

syntax error: invalid arithmetic operator (error token is “.c”)

I am trying to test if file "file1.c" is present in the current working directory, what am I doing wrong with my test command? I thought I understood this command, am I doing something wrong for the ...
-1
votes
3answers
44 views

Why am I getting an error “print_unicode: line 9: printf: missing unicode digit for \u Unicode 0187” with this script

I have written them following shell script to view what the Unicode characters look like on my terminal. #!/bin/bash X=0 while [ $X -lt 65536 ]; do HEX=`bc <<< "obase=16; $X"` ...