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

learn more… | top users | synonyms (2)

2
votes
2answers
79 views

Passing multiple of arguments with whitespaces through a script to ssh

I want to remove multiple files from remote server. I have all files under one array in a script and I call other script which will remove files. Let output of "${b[@]}" is: ...
3
votes
2answers
130 views

How do I remove all but the file name (with no extension) from a full file path? [duplicate]

I am presently writing a Bash function to convert all the man pages listed by equery files <PACKAGE> | grep /usr/share/man/man (if you are unfamiliar equery is a tool used on Gentoo-based ...
1
vote
3answers
36 views

script not running as expected when scheduled as a cronjob

I'm trying to write a script that will identify corrupt jpg images using imagemagicks identify command. The script will run the command, grep the output for the word "Corrupt", move it to a corrupt ...
1
vote
2answers
43 views

Add Line of Text to Section of Rules File

I'm trying to write a bash script to automate the install of nginx with pagespeed module. Part of this requires me to add this: --add-module=$(MODULESDIR)/ngx_pagespeed \ to a section of the ...
2
votes
2answers
43 views

Check Input Prior to Executing a “for loop”

is there any way to check or test the input from a 'read' against a for 'loop'? I don't want the case statement to execute there any of the input is incorrect. As of right now it will loop through, ...
5
votes
3answers
646 views

File name beginning with - (dash) [duplicate]

I have file called -l in my directory now I tried to do for i in *; do stat -c "%s %n" "$i"; done it lists all files with sizes but in the middle of the output there is something like 395 ...
1
vote
1answer
62 views

wait for predefined time before exit the script

I have an app server running in my unix box with process name as abc_test. I have a shell script in which I have to stop my server using /opt/abc/bin/stop. Now sometimes my server doesn't get stopped ...
0
votes
3answers
38 views

Matching lines in two files [duplicate]

Let's say I have two files, file1 and file2. file1: passd:xxx hopla:alli gnar:gungg araf:utap file2: alli utap How can i check what lines/words from file2 match file? Indeed I could probably do ...
2
votes
2answers
211 views

Solaris using sequence generator at the beginning of each new line

I am new to shell scripting. I created a script that extracts data from a database and loads it to a csv file. I am using SunOS hstz1454 5.10 system. I am trying to do a sequence at the beginning of ...
5
votes
3answers
106 views

Auto increment filename

I have a need to collect some duplicate files and want to avoid name collisions. The problem is that this collection of files might be added to by another execution of my script before the files are ...
1
vote
1answer
28 views

handle large number of same log using cron or logrotate

We have an app deployed in a server, which, under some scenarios, generates some logs in the below format. process_name.hostname.common_text.log.{error/info/warning}.date.time Now, due to this ...
3
votes
4answers
412 views

Sum of all Integers between two numbers

I would like to type in two numbers and get the sum of all integers between those two numbers, inclusive. For example: ./sum1 2 5 should yield sum: 14 because 2+3+4+5 = 14 Here's what I have ...
-1
votes
3answers
85 views

bash script to login to multiple Linux servers and collect the output of multiple commands through ssh [duplicate]

I need to login and collect output of below commands from multiple GNU/Linux servers through SSH. I have done password-less SSH authentication. I wanted to do this with bash script. df -lh | awk '{if ...
3
votes
3answers
159 views

I need to take the output of command and make it the name of a file using a script [duplicate]

I am working on a way to integrate our Linux machines into our SCCM Reports. One of the things we would like to do is verify the swap size on the machines. I know that I can get the swap amount on ...
3
votes
5answers
75 views

How to process special characters in in file name using find

I am to find all files that start with certail char , e.g find . -maxdepth 1 \( -name "^m*" -a ! -name "g$" \) -print but what if someone create file that has special characters in the name of that ...
1
vote
2answers
154 views

cat command is not working inside shell script

I have the following line which is not working in ksh but works fine in sh cat `find /home/peter/databases -name "cells.txt"` This is working if this line is inside /usr/bin/sh script. But not when ...
2
votes
2answers
49 views

how to login using ssh with password? [duplicate]

I want to login using ssh and password store in a text file or may be in a varible I am trying below method but i am getting an error please suggest me correct way. echo "123456" | ssh ...
2
votes
1answer
15 views

Script to see /mysqlshare is present in all list servers, doing only first iteration

I need to get /mysqlsharedetails from all the MySQL servers. I have written a script using a while read loop, but it's getting the details of only the first server, #!/bin/ksh ...
1
vote
1answer
36 views

Extract fields of a line into shell variables

I have a few hundred lines like below in connRefused.log:- 2015-12-12 00:12:10,227 ERROR [Testing-KeepAlive-01] c.v.v.v.Connection [Connection.java : 001] failed to bind to ...
0
votes
1answer
33 views

Script with variable in path

I'm not entirely sure where to ask or how to formulate this question with correct terminology. I have script here for managing a game (minecraft) server for the user (bukkit). I've cut out some ...
1
vote
1answer
32 views

A command that takes a single numeric argument and prints out the day of the week based on the formula

days=('Sunday''Monday') days=('Tuesday''Wednesday') days=('Thursday''Friday') days=('Saturday') for numbers in "S@"; do if [ $numbers -ge 0 ]; then result=$(($numbers ...
0
votes
1answer
47 views

Shell script to list the first or last n lines of a file

I want to write a script that lists either the first n lines or the last n lines of a specified file. cd $1=filename $2=string $3=lenght if [ "$filename" == "head" ] #If the ...
0
votes
2answers
41 views

Using Timeout in a Script with One Command, but Multiple Hosts

I'm writing a script that SSH into a device, SCP a file over, names it according to the device name and then goes on to the next one. My problem is if a device is not reachable the script hangs ...
3
votes
2answers
56 views

Changing file permissions according to their names

I created 512 files, with names made from combinations of permisions (r, w, x). I created them like this: touch ./{r,-}{w,-}{x,-}{r,-}{w,-}{x,-}{r,-}{w,-}{x,-} and I want the files to have same ...
1
vote
1answer
73 views

How to extract date and calculate if it is within “x” days from today?

Currently I have file with structure as Foo Sign: blah SubFoo Sign: blah BarDate: 2017-11-31 Foo Sign: blah BarDate: Never Foo Sign: blah BarDate: 2016-12-20 Foo Sign: blah ...
1
vote
1answer
40 views

How to echo/print the last iteration in this loop

#!/bin/bash cat /usr/local/nagios/libexec/std_filesystem.txt | while read line do if [ -d $line ]; then file_system_name="-p $line" new_file+=" $file_system_name" check_filesystem="$new_file" fi ...
3
votes
4answers
65 views

Word count bash script

I have this program that I want to tell the user how may time a user inputted word appears in a file. This is what i have written so far but it doesn't work. #! /bin/bash echo "Enter the file that is ...
0
votes
0answers
98 views

certificate error while Adding Hosts in Icinga monitoring tool

I am getting certificate error while Adding Hosts in Icinga ! I am very new to it so not able to figure out the error but I have received proper keys and certificates from client ! sh -x ...
5
votes
3answers
165 views

OR in `expr match`

I'm confused as to why this does not match: expr match Unauthenticated123 '^(Unauthenticated|Authenticated).*' it outputs 0.
0
votes
2answers
27 views

How to auto run script upon driver reboot?

I am trying to set an auto run on my shell script (named driver_check.sh) which will trigger upon rebooting the driver. Basically, my script is as shown below: #!/bin/bash echo "Start script" ...
1
vote
0answers
36 views

Unix: C-shell:Disk space checking in Hp-UX

i have 10 devices that using hp-ux and i want to check the disk space in each devices. my requirement is if the space more than 90%, the info of device ans space will be save to a log. this is list of ...
2
votes
1answer
83 views

ksh: for loop to loop through files in a particular directory

schema_dir=schema_app for SCHEMA_CHANGE in $schema_dir/* do so my pwd is /A/B/C/scripts within which I have subdirectories (schema_app, schema_data, etc). I want a for loop to run through the files ...
3
votes
3answers
54 views

A bc problem about long expression

I want to calculate an expression in shell. I use the following code: pi=$(echo "scale=10; 4*a(1)" | bc -l) i=3 d=`expr (1+c($pi*($i/10)+$pi))/2 | bc -l` But it says bad pattern: ...
3
votes
2answers
30 views

Date change format in unix

I am passing date as variable in function. I want to convert that date in different format. Example DT=2015-12-08 Want to convert DT to 08-dec-2015 in Unix.
2
votes
2answers
57 views

Unix calculator.bash having problems

This is a bash script I made to calculate numbers in Unix: echo "Please enter the calculation(operation) type (+)(-)(*)(/)" read $opr echo "Enter the first number" read $num1 echo ...
4
votes
5answers
99 views

Best way to partially step through a 25k string?

I have a 25k characters. I wish to write a script to print (printf is most portable I'm told) an arbitrary number of characters; stepping through them in order. say: command number Where number ...
0
votes
1answer
48 views

Raspbian: evaluate conditional strings and/or numbers

I am having a really a hard time to evaluate conditional strings and numbers. After hours of reading and trying with (my Beginners Guide) I keep getting the error msgs like syntax error in conditional ...
0
votes
1answer
29 views

writing of user's input with loop into text file

echo -n "##### STATIONS? #######" read station awk -v input="$station" ' BEGIN { n = split(tolower(input), user) fmt = "%-4s\n" } {print} /stab_site clear/ { for (i=1; ...
2
votes
2answers
61 views

How to find unique word in a single line

I have a string which is something like 50003 50003 50003 50001 this I get after processing into another file which is stored into a variable. now i want from that variable unique words. Like 50003 ...
1
vote
1answer
47 views

C Shell Script syntax error “unexpected end of of file”

I am trying to write a c-shell script that checks for number of arguments and echos a string, but I am getting an unexpected end of file syntax error and I don't understand why. Here is what I tried: ...
0
votes
1answer
40 views

Syntax error: Unterminated quoted string. Cannot find error

I'm writing a script to parse a larger file into usable data. I will attach the script below. The script was not running as I wanted and I thought it might have been the if/then statement I used, but ...
3
votes
3answers
87 views

Shell: selecting an available program

In bash/ksh/zsh, is there an good idiom to set a variable to the first of a list of alternative programs that can be found in $PATH (or otherwise callable by the shell)? For instance, if I have a ...
2
votes
1answer
86 views

Trying to send multiple text attachments via mail message

Running this script on: "Red Had Enterprise Linux Server release 5.11 (Tikanga)" Mail is: version 8.1 6/6/93 (appears quite old). Have tried various things and cannot seem to get this to work.. ...
0
votes
0answers
25 views

How to login one remote server to another remote server with different user name using different user private key?

I have 2 remote servers X and Y. I am able to login as user A with on remote server X using a private key. From server X to server Y I am also able to login as user A with the same private key. My ...
-3
votes
2answers
88 views

Unix Script For Telling The Day

I need a script that will tell me what day it is when I type a number representing the number of days since Sunday. e.g. 0 = Sunday 6 = Saturday 9 = Tuesday 130 = Thursday I guess this will need ...
2
votes
0answers
41 views

OS/X: can't execute shell scripts - spawns a new window which exits immediately

Issue: When I try to open any shell scripts a new window is spawned, which exits immediately. Files .bash_profile, .bashrc and a helloworld.sh are tested examples. Interestingly, running open ...
-1
votes
2answers
53 views

bash shell script two variables in for loop

for SLAVE_CLUSTER,MASTER_CLUSTER in $MASTER_CLUSTERS $SLAVE_CLUSTERS do echo "Master cluster boxes are ${!MASTER_CLUSTER}" echo "Slave cluster boxes are ${!SLAVE_CLUSTER}" done I am ...
1
vote
1answer
57 views

How to add users to Linux through a shell script

The shell script that I have to write has to create new users and automatically assign them to groups. This is my code so far: echo -n "Enter the username: " read text useradd $text I was able to ...
0
votes
0answers
25 views

Canvas(blackboard)-like program

I have to make a program that has most of the functions those websites have and I am stuck at the point where I have to get the grades from a file and use a formula to calculate the students final ...
0
votes
2answers
51 views

Parsing a Blocked file and generating smaller files

I have a file like below: 1weather dnsndjsdn 2nm bdbdb bdbdbdbdnnd 3gfdu hsihdishdis 5 1hdohdsohsoihssodhoishs 2nfdksnkdsnfsdsjndkdj 3kjdscdskndskjndndsdsdsd 5 Like wise I might have close to ...