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

learn more… | top users | synonyms (2)

0
votes
1answer
27 views

play a simple ding-dang sound in terminal

I have written a few scripts to be run under a bash environment. I would like to play a sound at certain times or after certain commands are executed and results are ready. This could be something ...
0
votes
1answer
44 views

How do I compare the day of the week?

I'm trying write a script which shows right statement based on which day of the week it is. Two examples: If today is 4th day of the week. echo Today is a working day. If today is 6th day of the ...
4
votes
1answer
132 views

Perl regex get word between a pattern

I have a working perl regex using grep. I am trying to understand how it works. Here is the command command. grep -oP '(?<=location>)[^<]+' testFile1.xml Here are the contents of ...
-1
votes
2answers
35 views

How to run same process with passing different parameter?

i try to run the below command at the same time but only first one can run but second one get blocked by same process id. sh ./controller.sh $myfile/a.sh start '1' 'today' sh ./controller.sh $myfile/...
0
votes
1answer
25 views

Password protected zipping command is not working

I have a assignment to create a password protected zip file from script and sent it over email. I am using below command over sparc-sun-solaris2.10 environment to create a password protected zip ...
-6
votes
2answers
49 views

Adding a space after the first character [on hold]

I have string like this 8prob566459 Required output : 8 prob566459
0
votes
0answers
14 views

custom init.d script works using sh -x <script> stop but fails when called directly or with service.. why?

I have a custom service and wrote a simple init.d script, serverE. (pasted below) All the service does is start up on a defined port and listen for connections. The problem is when I run either "...
4
votes
6answers
579 views

How to concatenate three files (and skip the first line of one file) an send it as inputs to my program?

There are file A, B, C. I want to concatenate file A, B and C (Skip first line of C). And then send them to myProgram as input. How can I write this in shell script? I wrote that cat A > file ...
-1
votes
0answers
17 views

bash script to collect the health check informations from multiple remote systems to one linux server without ssh passwordless authentication [on hold]

Please help me to create bash script to collect the health check informations from multiple remote systems to one linux server without ssh passwordless authentication. I do not want to do the ssh ...
0
votes
1answer
33 views

inserting gaps in a text file using shell script

How can I insert gaps at certain places in a text file using shell script? For example, I want to insert enter after word "complete" wherever it is found in a text file.
0
votes
1answer
42 views

Word generation with nested loops

I made this script which generates all combinations of lowercase letters and numbers and echoes them. It works, but I am wondering if there is a way to simplify the process of adding a new char ...
0
votes
1answer
25 views

Bash script for restart binary on error [on hold]

I wrote a small service in Go which must keep running always. But it's full of bugs, which sometimes lead to crash. Nevertheless, I want it to be restarted on any error and log errors to file. I think ...
-1
votes
2answers
38 views

POSIX way to add two numbers together without external program? [on hold]

I'd like to POSIX-ly add two numbers together in my shell script. I know I can do this: a=1 b=2 sum=$((a+b)) But if I try that with ` (i.e. sum=`(a+b)`), it doesn't work; and the $( ... ) syntax ...
4
votes
2answers
46 views

reference shell variable $COLUMNS from inside a bash script

This runs as expected in an xterm: sha512sum <filename> | cut -c -$COLUMNS, but not within a #! /bin/bash script such as dothis.sh <args>, because $COLUMNS is not known, so to say. I'd ...
0
votes
1answer
42 views

Copy contents of one script to another script

I'm very new to UNIX and I'm currently trying to learn Bash. I have 3 scripts: xyz.sh, abc.sh & wow.sh. I want to copy content of xyz.sh as it is to wow.sh using abc.sh, i.e., a script to copy ...
3
votes
4answers
56 views

Pass multiple command line arguments to an executable with text files

I have a C executable that takes in 4 command line arguments. program <arg1> <arg2> <arg3> <arg4> I'd like to create a shell script that continually runs the executable with ...
0
votes
1answer
42 views

How to Check a Process is Running on Another Server

How do I go about checking that a certain process is running in another box and return a value? For example, if I wanted to check that process 'FTP' is running in 192.168.1.1 from box 192.168.1.2, how ...
-2
votes
3answers
58 views

Bash script : How to export file name as header to csv

I have multiple .txt files in my folder " Subj1 " arranged in following format regional_vol_GM_atlas1.txt regional_vol_GM_atlas1_prop.txt .... regional_vol_GM_atlas152.txt each file ...
0
votes
1answer
27 views

Rsync behave differently if invoked inside script

So, I'm writing a backup script, and wanted to skip .iso files. If I use the command from the command line, everything works fine: rsync -a --delete --exclude='*.iso' /home/user/Desktop/Work /mnt/...
-1
votes
1answer
21 views

Unexpected end of file in shell script [duplicate]

Here's my script #! /bin/sh source=/Source/$1 destination=/Destination folderParam=$(basename $source) if /usr/bin/rsync -avh -r $source $destination; then cp /FolderCopyStatus/Success /Status/...
0
votes
1answer
56 views

How to find and join broken string

I have a task to search and join broken strings in configuration files on multiple servers: Configuration file contains many parameters and a section of it has few broken lines, which needs to be ...
0
votes
3answers
33 views

Date Difference Calculation [duplicate]

I am looking to calculate time difference between the two below Value1=2016-10-13 14:19:23 Value2=2016-10-13 18:19:23 I want to get difference in the form of hours/minutes. Any quick solution ...
0
votes
1answer
25 views

repeat google search with omitted results in shell script

I have a shell script that pulls google results for a specific search query. For some search terms google only returns a few results and says "In order to show you the most relevant results, we have ...
1
vote
1answer
36 views

naming split files using split command [duplicate]

I am writing a shell script where I am reading all the files in a directory, performing some criteria checks and splitting certain files on number of records (lines) I want to split file abc.txt as ...
0
votes
0answers
28 views

BusyBox - Bash signal handler 'echo' issue

I have a Bash script that begins by opening a TCP client socket using nc and sending a start command over that socket. The server then sends me back data over the socket (which nc prints to stdout), ...
0
votes
1answer
35 views

How to pass a variable log as an argument to a script?

I am trying to pass a log as an argument to a script that does the following: #!/bin/bash filter(){ grep -E "ERROR|FATAL|WARN|Caused|^[[:space:]]" /app/me/logs/$1 } #read varName filter > /app/...
0
votes
3answers
52 views

Beginner shell scripting question

This Linux program is supposed to print 0 to 4. But I'm unable to find error in this code. Please help. #!/bin/sh a=0 while [ $a -lt 5 ] do echo $a a='expr $a + 1' done When I try to run ...
-1
votes
1answer
53 views

Shell script returns 126 exit code from crontab

Crontab Entry: SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin * * * * * /FinalSync.sh $(/bin/date --date="5 days ago" +\%d_\%m_\%Y) || echo $? >> log OR * * ...
1
vote
1answer
52 views

Bash script - Automatically enter user input (password of keystore)

I know this has been asked before but almost only workarounds have been provided. None that solved my problem just yet. I'm trying to create my own .sh file which will generate an apk. After using ...
3
votes
1answer
58 views

Shell script not running in crontab [duplicate]

Following is my crontab entry SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin * * * * * /FinalSync.sh $(date --date="5 days ago" +%d_%m_%Y) || echo $? >> log ...
0
votes
2answers
23 views

What is the right way to expand these bash strings to the right Git commands?

I am having a go at writing some basic bash scripts and the expansion of these strings into Git commands is proving problematic. The idea is pass the script a top level directory whose sub-...
0
votes
3answers
74 views

Can a bash script tell what directory the user is when they run the script?

Is it possible for a shell script to know the directory the user is in when they run it? I am trying to develop a script like this which runs through a list of subdirectories and runs some git ...
1
vote
1answer
24 views

How to handle back arrows, End and Home keys in a read prompt

Using read and by typing `word followed by the left arrow ←, one get $ read word^[[D The same goes for the Home and End keys that lead to ^[[H and ^[[F respectively. How can I handle those ...
0
votes
1answer
16 views

Bash: centos script to check disk usage in percentage only [closed]

i have to do this script ./myscript.sh /a/dir1/vol/vol0 4% i need to create a script then run it while typing the directory of mounted volume in the same line. then it should show only the percent ...
0
votes
0answers
25 views

What is the command “.”? [duplicate]

While looking for a place to put my aliases in ~/.bashrc, I found this: # Alias definitions. # You may want to put all your additions into a separate file like # ~/.bash_aliases, instead of adding ...
1
vote
4answers
67 views

Change specific part of file via a shell script

What is the simplest way to search for a word in a file given in the command line, with this format ./<file1> -f <file2> --edit <id> <column> <value> I want to search a ...
0
votes
1answer
28 views

renaming binary files in multiple subdirectories using awk

I'm really pretty new to programming so bear with me. I've been trying for quite some time now with no success to rename multiple files which are located among multiple subdirectories. Some background:...
0
votes
0answers
25 views

Making entry remotely

In my envirement there are about 1000 production servers. Direct root login is disabled on all servers. There is one user "abc" which is having sudo access. We login to each computer using "abc" ...
2
votes
1answer
54 views

Can Bash Variable Expansion be performed directly on user input?

In bash, is there any way to read in user input but still allow bash variable expansion? I am trying to request the user enter a path in the middle of a program but since ~ and other variables are ...
-6
votes
0answers
34 views

Bourne again Shell Script [closed]

im a student just new in the Operating System clss....i need to know all these...can anyone help me in providing a sccript .... When executed the user should be presented with a menu with 4 (four) ...
-5
votes
1answer
33 views

Numerical Integration Bash script [closed]

Write a bash shell script which uses numerical integration to evaluate an analytic function. For the numerical integration use mid point rule. fixed interval, the midpoint approximation is as follows: ...
0
votes
1answer
52 views

Command line to send email if CPU load is high

I want to write a one liner on the terminal to send email if cpu load is high. I have this one but its send everytime its run while true; do lsof -u nagios | wc -l; b=15; a=$(uptime | awk '{...
4
votes
6answers
193 views

How to get this substring on bash script?

I'm working on bash script. I have a var with a string in it. This is the string: tSA_15_20161014_11-12-50 Basically the format is tSA_(id)_(year)(month)(day)_(hour)-(min)-(seg) Important ...
4
votes
2answers
292 views

base10 doesn't work

I recently started into bash scripting and tried to program a script to count from 0000 to 9999 - quite an easy task, I thought. Then I ran into the problem with bash taking 0007 as an octal and ...
0
votes
2answers
44 views

find the line number in a file starting with a pattern from current line [closed]

How to find out the line number which starts with date in yyyy-mm-dd format from current line number? In the example below, i wanted to find out the line number of the line starts with 2016-10-09 gggg ...
1
vote
2answers
34 views

Collect awk output in bash script for processing

I have a loop in a bash script that processes a number of files in a folder. In my loop, for each file, I execute the below line: awk -F":" '{ print "Name: " $1 "\t\tID:" $3 }' $file I would like to ...
1
vote
1answer
25 views

Joining two file data based on column comparision

I have two files each containing a timestamp and a count as follows File1.txt 9 2016-06-22 3 2016-06-23 2 2016-06-24 1 2016-06-25 2 2016-06-26 2 2016-06-27 File2.txt 3 2016-06-...
0
votes
0answers
33 views

command not found in shell script

I am running a shell script on my server. Below is the script: #!/bin/bash #----- cd /change working directory cd /Net/Groups/BGI/people/sbesnard/PhD_MPI/RO1/Rproject/Landsat_Processing/Scripts/ ...
1
vote
1answer
26 views

mysql backup and rsync script problem

I have a bash script to backup MySQL databases and then rsync them to a remote location. Last night this failed spectacularly and filled up the home backup-db directory with 33GB! I have the script ...
1
vote
0answers
10 views

display unix variable with dbms_output.put_line

I have a loop with while that is reading a file and then make a query of these value but when I'm trying to show a message with dbms_output.put_line it says me : dbms_output.put_line(henry); ...