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

learn more… | top users | synonyms (2)

-3
votes
1answer
38 views

find all .sh files then copy to <date>scriptbackup

Locate all the .sh scripts you have created in your Linux installation (searching recursively if needed – excluding existing backup folders) It will then copy them all into a folder called ...
-2
votes
0answers
19 views

shell script to know the status of a node's application, whether it is up or down [closed]

I want to know the status of an application and application server which I cant get directly. It is like connecting to a server lets say 'A' and that server has many nodes say A1.A2,A3 and in that ...
1
vote
1answer
50 views

Print lines between two patterns matching a condition in awk

How can I print lines between two patterns which meet a certain condition? For instance for an input file partially containing the following: Time %MEM %CPU %SWAP 00:05:02 7.3 ...
-1
votes
0answers
29 views

Count how many times a word occurs in a txt file with awk

Basically i'm trying to count all instances of certain words that occur in a text file then printing the result. It has to be in done using awk. Im not really sure where to start. Any suggestions?
-4
votes
0answers
29 views

Random password generator [closed]

Make a random password generator: read 3 to 5 random lines from /usr/dict/words and assemble them together to form a random password. the command should takes an optional minimum size argument that ...
1
vote
1answer
48 views

getopts passing value of declared parameter to function

I have function port.sh as stand alone script and i'm wondering if is possible to put this function in the same script where getopts is and pass value of OPT_B into function and get output of it? ...
0
votes
2answers
41 views

How to call on 3 scripts inside a shell script

I am battling to run a shell script which has 3 scripts which it needs to call and execute one after each other as soon as the execution completes successfully (error: gzip:.gz: unexpected end of ...
0
votes
3answers
51 views

Parent script continues when child exits with non-zero exit code [closed]

I have a script that calls another script. When the child script fails, I'd like the parent to fail as well. In the child script child_1.sh, I have something like this: if [ $SOME_BAD_CONDITION ] ; ...
0
votes
2answers
63 views

Read line from a file

Hello how can i read each line from a file and compare it with other file... Actually that file should be taken from command line.... please help me out if [[-f $@ ]]; then for "$line" in $@; ...
4
votes
2answers
241 views

Delete files older than specific file

I need to delete from a folder all files older than a specific file. Running bash on CentOS 7. I have a solution for this, but I think there should be a more elegant way do it: ...
1
vote
2answers
48 views

print the output of 2 commands in 1 file on the same line

Thanks for looking at this. I have a possible simple question, but I wasn't able to find any help so far on the internet. I have a script that has mainly 2 commands that process output. But both ...
1
vote
2answers
70 views

Search for matching files with wildcards without using find in a bash script

For an assignment, I'm supposed to write a bash script that can act as a very basic find, but without actually using the find command. For example, if I put in this input: my_find ~/homedir/ -name ...
1
vote
1answer
31 views

Shell script to change directory of terminal and open a second terminal

I am new to writing shell scripts and I am trying to write a script to CD to a folder where my programs are saved for one of my classes, then have a second terminal open that ssh's to a server used ...
0
votes
1answer
32 views

How can I multiply a column by a variable and write out? [duplicate]

I would like to multiply a single column in a .txt file by a variable and then write to another .txt file. What am I missing from the awk line? Appreciate any help in advance. !/bin/bash ...
-1
votes
0answers
56 views

Send mail from BASH/SH file with mailx - mail is not being send

Hello I have this script in a file: #!/bin/bash # email subject SUBJECT="New_fish.app_available" # Email To? # Email text/message EMAILMESSAGE="/tmp/emailmessage.txt" first_line="There's a new ...
7
votes
8answers
2k views

Is there a unix command that gives the maximum of two numbers?

I was looking for a command to limit numbers read in from stdin. I wrote a little script for that purpose (critique is welcome), but I was wondering if there was not a standard command for this, ...
1
vote
0answers
35 views

How do you derive a decimal from a math operation involving a variable?

I'm trying to find derive SCALEFACTOR which is basically 10000/(sum of 4th column in a file). How do I get a decimal from the output? Appreciate any help in advance. #!/bin/bash ...
1
vote
3answers
68 views

How do you parse through a subdirectory where the path contains spaces? [duplicate]

I'm trying to parse through a set of files in a directory on a mapped drive. However, I can't seem to resolve an issue that seems to be because of spaces in the path to the subdirectory. Would ...
0
votes
2answers
31 views

A batch that cout the number of occurrences

I've to extract the number of words using each letter of the alphabet from A to Z. The script that i've to create create take as parameter the name of the dictionary file to analyze and will be used ...
1
vote
2answers
71 views

Is there any way to make scripts dynamic? [closed]

I need my script to show the time till next run, continuously like a timer, is this possible?
2
votes
1answer
55 views

Bash script to detect uploaded files triggers many times for one file

I have a simple bash script setup that uses the built-in inotify daemon running CentOS 6.6. The script will simply echo the file that is upload to a specific directory. The script works but it echos ...
0
votes
2answers
54 views

help with bash scripting tput getting errors [closed]

I am a beginner to bash scripting. I need help to figure out what is wrong with this tput menu. #!/bin/bash tput setb 3 tput clear function main_menu { option=0 until [ "$option" = "4" ]; do echo ...
0
votes
1answer
72 views

bash if, then and else statement

I am learning bash, I ran into a small problem when trying to write a small script #!/bin/bash clear read num if [ "$num" -eq 2 ] then [ -d "/etc/passwd" ] | sudo cp /etc/passwd /home echo ...
1
vote
2answers
86 views

How do I automate opening Firefox over an ssh tunnel?

My university has access to some academic journals that I cannot access from home. To be able to download papers while I am away, my current proccess is: Create an ssh tunnel to my university ...
1
vote
3answers
56 views

loop test strings to see if input is valid for C program input

For example I have a file filled with some pretty gnarly strings. 12345678900 1111111111111111111111111 ...
0
votes
1answer
33 views

shell scripting and running after switching to other user

I have the following commands that I want to have them all in one shell file: su – s3 lizinfo.sh –b when the first linex executes, it prompts and the command prompt become like as below: ...
2
votes
1answer
67 views

Bash - Split quoted parameters

I have a script which gets called with two parameters: ./script.sh a b I'm currently reading them through $1 and $2 (such as cd $1). My problem is that the output needs to be the same for when the ...
2
votes
2answers
41 views

Why `until` block is designed as it is just a negative version of `while`?

To my understanding, until block is just the opposite version of while, like until "condition A is met" is equivalent to while "condition A is not met". In some modern languages such like python, ...
2
votes
2answers
124 views

Bash menu with multiple parameters in one row

I have searched a couple of days and still didn't found the answer. I hope that you can point me in right direction. I would like to know how to write a bash script with a options, that can be ...
7
votes
7answers
181 views

What is the purpose of having two variables ($@,$*) to transmit the arguments of a command into a script? [duplicate]

I have read of the special variables used in a script $@ and $*. As far as I understand, the arguments used while executing the script are stored into two special variables, once all arguments into $@ ...
0
votes
1answer
15 views

Calling of scripts between init.d and home directory of server

I have a script (server_up.sh)that automatically makes server up whenever server gets rebooted and is placed on linux server in home directory. I have made another script "up_server.sh" in init.d that ...
1
vote
2answers
44 views

How to format decimal number to display the preciding zero but not the trailing ones?

I have the following script on Ubuntu 14.04.1 LTS 64-bit bash command prompt: S=0.030 F=0.150 N=10 reso=20 DIFF=`echo "scale=3; $F - $S" | bc -l` df=`echo "scale=3; $DIFF / $N" | bc -l` is=`echo ...
0
votes
1answer
51 views

capture the id of the process which called the function inside the function

I want to log the ID of the process which called a specific function in Korn shell scripting. eg Lets consider an user-defined autoload function SQUARE. Now if a TestSquare.sh script calls SQUARE ...
2
votes
2answers
53 views

menu script over ssh

I have a script that asks for input from the user. When I run this locally it does what I want however I'd really like to run it over ssh. I've tried the regular ways I'd run a script: ssh ...
2
votes
2answers
64 views

How to extract the positive numbers in the first column from an output as in the question?

I am running Ubuntu 14.04.1 LTS 64-bit with Bash 4.3.11(1)-release I have a program called harminv producing output as follows: $ h5totxt hsli0.126.h5 | harminv -vt 0.1 -w 2-3 -a 0.9 -f 200 # ...
1
vote
2answers
67 views

How to list only JPEG files from root below using the command line ?

I am searching for a method to find only JPEG files, With my limited knowledge of Linux I came to this point: 1. list all paths that exist from root below with find / 2. pipe the result into next ...
6
votes
4answers
507 views

Why is it “while kill -0 $PID” and not “until kill -0 $PID”?

I may be being daft here, but if I want to do something while a process is running, why do I do: while kill -0 $PID do #... done instead of until kill -0 $PID do #... done ? kill -0 ...
3
votes
1answer
42 views

shell script is executed twice

I have this small code snippet in a shellscript to set a password: if [[ -z "${PASS+x}" ]]; then read -p "enter pass or use default [test1234]" PASS if [[ -z "$PASS" ]]; then ...
1
vote
0answers
27 views

What is the first event/file/log in linux that appears/changes on boot that signalizes network being up?

I have a vSphere farm with virtual machines and python script that handles cloning and managing of those VMs. I also have a machine (RedHat 6) that I clone if I need a new one. It has a script that ...
2
votes
3answers
84 views

What is a best practice to represent a boolean value in a shell script?

I know, that there are boolean values in bash, but I don't ever see them used anywhere. I want to write a wrapper for some often looked up information on my machine, for example, is this particular ...
1
vote
3answers
44 views

How to convert bash shell script to Markdown?

Imagine one has been working on a bunch of deploy scripts. These shells scripts are heavily documented with comments and links and are meant to be read by humans. Wouldn't it be handy to convert ...
14
votes
4answers
608 views

What is the difference between '$ . foo' and '$ ./foo'? [duplicate]

t is a simple script What is different between two case below : $ . t and $ ./t
0
votes
1answer
31 views

Where to “install” node application and best way to launch

I'm pretty new to the Linux world, I have a Node application that I would like to distribute through an apt repository, this is what I do for now: Put the node binary inside the Node application ...
2
votes
0answers
38 views

Display cron job times in a human-friendly format

Is there a way to display or is there a tool that can parse a crontab expression and display it in a human-friendly way? 10 6 * * * sh /usr/local/crons/file_check.sh For example, for the above cron ...
0
votes
1answer
26 views

Why can't I see the output of scripts ran using ForceCommand in sshd_config? [on hold]

I set up sshd_config with ForceCommand /path/myscript.sh for the user "tester": myscript.sh: #!/bin/sh echo test1 echo test2 | tee -a /home/tester/test.log The script is executed properly on login ...
-1
votes
1answer
48 views

I'm trying to create a script to send message “hello” to file name Hello in home directory

And display the contents of the file in the stdout using #!/bin/bash #!/bin/bash echo"hello" >> ~/Hello cat ~/Hello should I use tee ~/Hello to display contents of file Hello in stdout ?
2
votes
1answer
53 views

ssh and run script on remote host and answer expect answer automate

The ssh from server0 to (server1,server2,server3) (no password need to SSH (trust exists between all servers and private key exists on all servers)) but a remote script on server (server1,server2 ...
2
votes
2answers
48 views

Bash command: is it possible to pass an argument before a custom command (function) or it must be only after:

I am wondering if it is possible to pass an argument to a custom command before the command? Let say I have custom command ping and I would like to pass the IP address before command: instead ping ...
1
vote
1answer
46 views

I want to create a cron job that runs a command on a remote linux box using ssh but I want ssh to answer password [duplicate]

Thank you for the reply.This is not what I am after. The ssh from server 0 to (1,2,3) (no password) but a remote script on server (1,2 & 4 ) which starts a service/application needs a password for ...
0
votes
2answers
87 views

Shell script for ssh into a Unix/Linux server from MacOS X 10.10

I am attempting to ssh into a server by using a bash script from MacOSX. #!/bin/bash spawn ssh username@gatewayserver expect "password" send "Mypassword\r" interact spawn ssh ...