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

learn more… | top users | synonyms (2)

-1
votes
3answers
71 views

How to catch with RegExp first word with different first symbol in it using ed text editor

I have shell command: printf '/^PermitRootLogin/\nc\nPermitRootLogin no\n.\nw\nq\n' | ed -s /etc/ssh/sshd_config And I need catch #PermitRootLogin like PermitRootLogin but not commented paragrath ...
4
votes
5answers
201 views

How shrink test -eq expression with more than one var value in /bin/sh

#!/bin/sh if [ $num -eq 9 -o $num -eq 75 -o $num -eq 200 ]; then echo "do this" elif [ $num -eq 40 -o $num -eq 53 -o $num -eq 63]; then echo "do something for this" else echo "for other do ...
1
vote
2answers
60 views

Copy Files Based on Dates in Filename

I am having an issue when attempting to copy a range files from one directory to another based upon a date contained within the filename. The date in the filename is in UTC whereas the created dates ...
0
votes
1answer
28 views

copy a directory into multiple directories

I have structure like A directory dir_a/dir_b and dir_c/dir_d to dir_z or some other 100 names. now I need to copy dir_b into dir_d and all other sub-directories in dir_c. And a part from that ...
3
votes
1answer
34 views

reformatting command output within bash script

within script the attempt here is to remove the : and then revert the / to \ within the print out currently I have to display the linux path: The home directory is located here: ...
1
vote
2answers
62 views

shell stderr to /dev/null

I have PID file and I want to get PID number so this is what I am doing. [root@linux ~]# PID=`cat /usr/local/foo/var/run/foo.pid` [root@linux ~]# echo $PID 3414 sometimes this file doesn't ...
0
votes
3answers
75 views

If, elif and else shell script Linux statements

#!/bin/bash echo "Type in your username in lowercase letters" read user #sudo adduser $user echo "Are you a student or teacher?" read group if (("$group"=="teacher")); then #sudo usermod ...
1
vote
0answers
43 views

CSV copyscript not copying 5 files out of 4000+

I was provided a great bit of code for searching and copying files listed in a csv from a directory and its subfolders in an answer to my previous question. However, some files are not copied. The ...
0
votes
1answer
83 views

text to xls file creation

I have 4 text files in my unix system want to put data into a xls file and send it via mail. text1.txt: 100 150 130 120 110 text2.txt: 200 230 240 250 260 .. .. .. so on ... I want to have ...
1
vote
3answers
276 views

Creating a shell script inside a text editor

I want to know how to create a shell script inside a text editor. So this is what I have inside the text editor. #!/bin/bash mkdir -p temp cd temp if [ $1 > $2 ] ; then echo $1 else ...
1
vote
5answers
71 views

Creating a permanent variable

Is it possible to set "permanent variable" in shell? For example, when I log in I want to print message "Hello user, this is your xxx log in" The number of logins would be stored in permanent ...
1
vote
1answer
63 views

bash adds apostrophes to expanded variable

I am reading in a file inside my bash script where each line consists of multiple columns like this: ANSIBLE 'first run' '--diff --extra-vars "client=yes fast=no"' As you can see, the line consists ...
0
votes
0answers
63 views

How to use df -h for only for path I am currently using for copy files and put the output to variable?

I am looking for a way to check the disk space only for partition which I am using to backup some folders and files to. As an example: I am in folder /var/usr/local/foo and I need to copy this ...
0
votes
1answer
35 views

Checking for mails

I recently started using mails via UNIX. I would like to create a script , that would write (every time I log in ) something like "The content of your mailbox has changed since last checkup" ...
-3
votes
3answers
91 views

How can I check that two input values are correct in a bash script?

I am writing a bash script and want to add some simple validation tests. The input should be either 1 or 2 and the script should ask for input again until the correct input is given. I was thinking ...
1
vote
2answers
30 views

Shell script says system when to execute for the next time

I've got a shell script. It is supposed to be executed automatically on and on over time. Maybe about three times a day. But I don't want to write a cron job for it since it's not the same time every ...
0
votes
1answer
47 views

How to echo lines horizontally

I'm making a menu with various selection for the user to select, but as soon the row hits 10 the pattern changes. Since the number 10 has two digits of course is going to change patterns. I want to be ...
0
votes
2answers
57 views

Find command - argument list too long

Oracle Linux 5.10 BASH shell [oracle@src01]$ getconf ARG_MAX 131072 [oracle@srv01]$ ls -1 | wc -l 40496 #!/bin/bash # # delete files in /imr_report_repo that are older than 15-days find ...
2
votes
2answers
104 views

Bash Scripting: automate command in console

I am connecting to a VPN via a simple bash script, that I would like to run on computer startup, thus, I need it to be fully automated. However, the script will run "openconnect --jupiper" and ask for ...
1
vote
1answer
126 views

Bash to Call PHP, Wait for PHP Process to finish?

Here is my bash script #!/bin/bash timestamp() { date +"%T" } pushd 'httpdocs/DIR1/DIR2'; file="Lock3.key" if [ -f "$file" ] then echo "$file found, Session is already in progress" $(date) ...
16
votes
4answers
767 views

checkbashisms-compliant way to determine the current shell

In my .profile, I use the following code to ensure that Bash-related aliases and functions are only sourced if the login shell actually is Bash: # If the current (login) shell is Bash, then if [ ...
0
votes
2answers
61 views

create an array of dates in bash scripts and match it current date

Actually I want to create an array of dates and compare it to the today date if it match with the current date then execute test.sh file otherwise exit the loop in bash script. I did like this... ...
0
votes
1answer
66 views

Why does downloading bash script from pastebin not work? [duplicate]

I'm trying to upload and download a bash script from pastebin, upload was straightforward enough with copy and paste, download didn't go as easy. There are two scripts I'm trying to download, these ...
0
votes
1answer
44 views

Compare and tar file for 2 date formats from filename

I need to keep files 4 months from now (3 previous month + 1 current month) in directory and tar the rest. But the problem is my files consist of different format. StockList_03-01-2015.txt ...
0
votes
1answer
72 views

How to use negation of a command in a while loop with grep in shell script?

Is there any way to use while loop and grep all together? See my example: while [[ !(grep -R -h "${text}" ${path}) ]]; do ... done It says: ./test_script.sh: line 1: conditional binary ...
0
votes
0answers
18 views

Redirect stderr to stdout and tee to file and check return value [duplicate]

I know how to redirect stderr and stdout to a file: curl -sSo file http://foo.bar >> log 2>&1 I know how to get stdout to appear on the console and in a file: curl -sSo file ...
1
vote
1answer
55 views

Scripting SSH function getting `Connection refused` error

I am using fish as shell, ssh shortcut function as following: function sshec2 ssh -i $HOME/.ssh/key.pem -t -t "ubuntu@$argv[1]" end To ssh into specific AWS EC2 instance, I wrote command pipe ...
1
vote
2answers
37 views

Why does the exit command not exit from nested while loop? [duplicate]

I have the following script. It prints all of first characters to console from passwd, but my expectation was to get only one character and for the program to then terminate. #!/bin/sh cat ...
1
vote
2answers
53 views

How to use read command with question and variable alltogether?

How can I use read command to be able to use colors in part of the text and variable in it without using --dialog command in linux shell script? Example I need a question to appear like this in bash ...
2
votes
4answers
112 views

Go through every subfolder, check for a folder and run script

I have a directory that contains subfolders of various depth. I want to go through all of them, check if they contain a folder with a certain name, and if that directory exists run a script (let's ...
1
vote
2answers
57 views

How to extract a string from a file name?

I'm trying to read a part of a file name to make it in an if .. else statement for example : file name : foo_bar_test1_example.stat I want to do a test; if the word : example exists in the file ...
0
votes
2answers
40 views

How to get the psql table records in shell script?

I have postgresql, in that I have a table with 10 records, I want the 10 records in 10 local variables shell script. I tried with following way, but it will store all the records in list123[0] ...
3
votes
2answers
256 views

Alter certain bytes in many files

I need a large number of damaged .png files in order to test my project. To that end, I need to set all bytes from the 0x054-th to the 0xa00-th to 0. .png files contain chunks with checksums, I want ...
0
votes
1answer
46 views

Output is not getting written in nohup.out while starting the server from jenkins

I have written a shell script to start a server which is mentioned below and this script is executed from jenkins via ssh. nohup ./startWeblogic.sh & The server is getting started alright but ...
3
votes
2answers
74 views

What does '-size +0' mean in shell 'test' command

I came across a if statement like this: if [ -f <file path> -size +0 ] I know that -f checks for file existed, but what does this -size +0 do here? I can't get help form man page also tried ...
3
votes
3answers
121 views

/bin/cat: Argument list too long

I have 119766 files in a folder. They are CSV files. I want to find out total number of lines of all files. I'm trying to run following command: cat * |wc -l But the following error occurrs: ...
1
vote
2answers
70 views

bash - source without polluting own namespace [get variables from other scripts in a safe manner]

I'd like to assign the contents of variables of another bash script to variables in the calling script. Specifically, I source this file: ...
1
vote
2answers
64 views

bash - use a variable int value to refer to position parameter in a function

I would like to use a variable say: i=1 as a value to refer to positional variables passed to script, e.g.: x=101 y=201 z=301 foo(){ echo "$1" echo "$2" echo "$3" } foo x y z ...
0
votes
2answers
47 views

Awk run time error: not enough arguments passed

Here is the script: TYPE="${BLOCK_INSTANCE:-mem}" awk -v type=$TYPE ' /^MemTotal:/ { mem_total=$2 } /^MemFree:/ { mem_free=$2 } /^Buffers:/ { mem_free+=$2 } /^Cached:/ { mem_free+=$2 ...
1
vote
0answers
72 views

How can I switch from one user to another user inside a script?

.The issue is my id 'aaa' can read only the file name and not the contents inside it when I log in with my id "aaa". So to read the contents I have to switch to another user "bbb" which is having ...
1
vote
0answers
31 views

C shell. Make script wait for Gnome-terminal to finish

I am working on a script that has to process a lot of data. All comes down to 3 commands. I use: #!/bin/csh gnome-terminal -e "ssh $servername1 'command 1'" & gnome-terminal -e "ssh $servername2 ...
3
votes
6answers
521 views

Sane way of enumerating python versions from bash

Due to bureaucracy, I am in a situation where I can get someone to run a bash script on a Linux server and give me outputs, but I cannot log in there, or run the script myself. I am fairly certain ...
1
vote
2answers
65 views

CSV copy script error reporting in bash

I've got this script which copies files listed in a csv recursively from a main folder. The copying aspect of the script works perfectly. However, I now want to add some error detection functionality. ...
3
votes
4answers
156 views

Iterating through subdirectories and get two files as arguments for awk script

I need to iterate through the subdirectories of a directory and take two of the files, as arguments of an awk script. The script will compare the two files and generate other files. I've this. But I ...
1
vote
1answer
56 views

md5 hash only first 512 bytes of file

Background I am about to migrate files from my old NAS to a new one, and want to verify the data integrity. The old NAS (Debian) is using Linux Ext3 file system, whilst the new one (FreeNAS) is based ...
0
votes
1answer
53 views

how to use concatenate command inside the awk command

I am trying to print the multiple columns from the file with different sub commands with the awk command. Below is my command which throws error while using concatenate command with awk awk -F\| ...
1
vote
2answers
64 views

Script to send email alert only when process change state

Below script checks whether MStrsvr process is running or not . The issue I'm facing is if i schedule a cron tab to run this script for every 1 hour it will throw email alert every 1hr that "MSTRSvr ...
1
vote
1answer
77 views

syntax error near unexpected token `('

rhel_major=$(grep -Eoh [0-9]+\.[0-9]+ /etc/{issue,*release} | head -1 | awk -F'.' '{ print $$1 }') rhel_minor=$(grep -Eoh [0-9]+\.[0-9]+ /etc/{issue,*release} | head -1 | awk -F'.' '{ print $$2 }') ...
1
vote
2answers
76 views

How do I use a temporary environment variable in a bash for loop?

I want to run YII_ENV=prod yii kw/test ten times. I tried $ YII_ENV=prod for x in 1..10 do; yii kw/test done; -bash: for: command not found 1304682651 (Seemed to run once.) I also tried $ for x in ...
0
votes
2answers
68 views

Pausing and restarting all Python processes

I have a server which runs our backend scripts for our database (ETL processes, etc). However, for two hours a day we dedicate it to sending our e-mails. The e-mails are the top priority, however, ...