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

learn more… | top users | synonyms (2)

0
votes
0answers
5 views

Persistence Bash history between detached processes

I haven't yet been able to find this among the bash documentation so I was hoping it could get answered if I asked it here. Is there any way that I can, on execution of a script, branch its history ...
0
votes
0answers
15 views

How do I process new additions to logs

I know that I can use a few tools like tail and less to view the newest additions to a growing log file. What I want to do, though, is run some sort of script at regular intervals (like cron) on the ...
0
votes
0answers
48 views

Assistance with script on multiple hosts

I am running the below script on Server A. Before running this I read the following link: Generate an RSA key pair for version 2 of the SSH protocol #!/bin/bash HOSTS="serverA, serverB" ...
4
votes
3answers
207 views

Is it possible to echo into a file, but use indenting in the shell script source? [duplicate]

If I have some nested and indented statements that echo a multi-line string into a file, the indents from the original shell (in my case bash) will be carried over into the target file. To avoid ...
1
vote
3answers
44 views

Last exit status from within script without source

Supposing someone invokes a non-existent command, the only way I know to retrieve its error status from a script I execute right after is by using source I.e., let's say this script's name is dummy ...
0
votes
1answer
23 views

Run script from GUI with terminal output

I would like to run a script from the GUI. For example a simple echo "hello" from the right click context menu. In my case I would set up an action in thunar like this: Then it appears in the ...
4
votes
3answers
86 views

Redirect the tail output to a file then stop when match found

there is this log file that data coming in is continuous. what i wanted to happen is to tail -f this log file then redirect it to a file with the ff conditions example of the log files content ...
0
votes
1answer
21 views

assistance with scripting list of users

I'm new to scripting, so far I've created this: #!/bin/sh ( echo List of users in PRD echo $(date) cat /etc/passwd | awk -F: '{print $1,$3,$5}' | sort | \ while read username uid gecos do echo ...
-1
votes
0answers
28 views

Shell script for electrum - how to add the seed? [on hold]

I use a diskless web server with a live cd and looking for a possibility to restore my electrum wallets automatically by a seed. I would like to implement a script that performs this task for me. so ...
0
votes
0answers
17 views

URL Parameters with cURL code

I have been converting a .vbs script for use with CURL from an old domain to a new AD domain, and to post to a new sharepoint. I think I have evenrything correct except my destination. My output log ...
0
votes
0answers
18 views

output in columns [duplicate]

i am trying to put my data after a snmp walk in a table this is my code: for i in `cat $Rep_Scripts/IP_ALU_LIST.txt | awk '{print}'` do read hostname ip <<< $(echo $i |sed 's/;/ /') ...
18
votes
2answers
2k views

What's the point in redirecting output of grep to /dev/null?

Consider this line: ${libdir}/bin/licenseTool check "${SERIAL}" "${VERSION}" "${PRODUCT}" ${libdir} | grep '^200' >/dev/null What's the point of looking for the pattern in the output if the ...
0
votes
1answer
36 views

Add the number in the column if exists

I need to count Nodes_Util for each Queue. In the example below, queue1 has only one line, but it varies and it could be nothing sometimes and it applies to all queues. I want to dynamically add the ...
2
votes
2answers
32 views

how to strip the last slash of the directory path?

I have a script which requires an directory as one argument. I want to support the two form: one is like a/b/c (no slash at the end) and another is like a/b/c/ (has slash at the end). My ...
0
votes
1answer
34 views

How do I copy all files that have been created or modified in the last 12 months?

I would like to copy all the files created in the last 12 months to a new folder leaving behind everything else. Including sub folders.
2
votes
1answer
25 views

How to download a lot of documents on the terminal from a server?

I have to write a bash script (.sh) with less than 300 characters which downloads all of the genomes 22 in this server ftp://ftp.ncbi.nih.gov/genomes/Homo_sapiens/ (the ones with fa.gz extention) and ...
2
votes
3answers
32 views

Extract a part of a string in a bash script

I have a variable with some text in it. I need to get a specific bit of information out of it. For example I have export OUTPUT="Running \"protractor:admin\" (protractor) task Using ChromeDriver ...
2
votes
1answer
25 views

I have a multi-line string that I need to iterate over, but I'm not using bash. Advice?

I'm using Dash because this is to run on my rPi. Bash is not an option. I'm rewriting a Bash script to work with Dash. I'm hoping to make it as POSIX-compliant (portable) as possible. The thing is ...
1
vote
1answer
34 views

How do I capture output into a variable and still have it goto the screen too?

I can do OUTPUT=$(grunt test) and that puts the output into OUTPUT but it's no longer on the screen. I need to see the output as it comes as well, so I can't just wait and then echo $OUTPUT. How can ...
1
vote
0answers
10 views

Issues while eMMC partitioned using sfdisk

I am writing firmware(MLO,u-boot.img, uImage(ver 3.12), dtb, rootfs.tar.gz) programming script for am335x based custom board. Rootfile system is to be put onto the eMMC. Firmware programming script ...
0
votes
0answers
31 views

How to use a printf in awk with a delimiter? [on hold]

awk -F, 'BEGIN { printf "%2s %5s %5s", $1, " ", $2 }' file1 >> file2 How would this display, my thinking is that this would bring back: file1 has: 40,Car 50,Truck 60,Van file2 has: 40 ...
2
votes
4answers
102 views

How to combine two files into one with columns for each file's data? [duplicate]

I have two files: file1 contains: 1 2 3 4 file2 contains: John Sam George Ken I want to combine these files to create one file(file3) 1, John 2, Sam 3, George 4, Ken My thought was to use ...
2
votes
2answers
52 views

Joining bash arguments into single string with spaces

I'm trying to join all of the arguments to a Bash function into one single string with spaces separating each argument. I also need to have the string include single quotes around the whole string. ...
1
vote
1answer
17 views

Unable to replace variable in shell script using awk

I have been struggling to replace every occurence of "<KEY>" in a file with ${encryptedkeyValue} I wrote this line but it is not doing ...
1
vote
1answer
27 views

How to retrive a file from a prompt?

Suppose I wanted to create a script that would prompt for a file to be search for. Such that, echo "What file are you searching for?" read filename filepath=/test/dir1 file=$filename for I in file ...
1
vote
2answers
16 views

How to check if a group of files is readable?

I have to check if a group of files is readable. I know how I would go about checking one file by using [ -r file.txt ], but how would I go about writing a loop that would check multiple files ...
0
votes
4answers
40 views

Getting an error when running awk from a script

I have a file some.txt -rwxrw-r-- 1 ivamshky ivamshky 152 Apr 2 00:42 12.sh~ -rw-rw-r-- 1 ivamshky ivamshky 58 Apr 6 19:03 a.c -rw-rw-r-- 1 ivamshky ivamshky 98 Apr 1 20:27 all.sh ...
0
votes
2answers
58 views

Having trouble with basic if then statement

learning the basics of scripting and I have this line of code: #!/bin/sh if [ $# -ne 1] then echo "Please provide one directory to search" echo "Example usage: something.sh directory_name" ...
1
vote
1answer
32 views

Variables in dialog radiolist

I have the following dialog radiolist, which works fine. #!/bin/bash ch1a="1" ch1b="Fri, 20/3/15" ch2a="2" ch2b="Sun, 21/6/15" ch1="\"$ch1a\" \"$ch1b\"" dialog --title "Equinoxes and Solistices" \ ...
-2
votes
0answers
36 views

how to print only part of line using awk/sed/grep [on hold]

I need to print only part of the complete line after removing/omitting starting part. Can someone give me the regular expression to do so
3
votes
3answers
43 views

How to check if string is blank in tcsh

How can I check whether a string is empty in tcsh? Before you freak out, no I'm not writing shell scripts with tcsh. I am asking because I want to use this in my .tcshrc file. Specifically, I want ...
1
vote
2answers
36 views

CentOS 7 shell script interpretor

I am starting to write a shell script to be run in CentOS 7. Which interpreter should it call, and what should the shebang line look like? I tried this: #!/bin/sh But when I type cd /bin ...
2
votes
1answer
45 views

How to I prevent exec from keeping the script running?

I'm using exec like this: #!/bin/bash exec > >(tee /tmp/mylog.log) 2>&1 bash -c 'sleep 12312' & I want the output of the commands to be in a log file, and then I want to start a ...
3
votes
2answers
113 views

How to check if vim is installed?

I want to know how to check whether a command is installed. Specifically, I want to alias vi to vim on all machines where vim is a valid command. And I want to keep my *rc files generic. But some ...
3
votes
2answers
92 views

sed insert in the beginning of multiple files is not working

I came across a lot of answers, including theses: sed on OSX insert at a certain line http://stackoverflow.com/questions/14846304/sed-command-error-on-macos-x ...
1
vote
1answer
63 views

How to merge two files in the same row?

I have two files. file1: Dave 734.838.9800 Bob 313.123.4567 Carol 248.344.5576 Mary 313.449.1390 Ted 248.496.2204 Alice 616.556.4458 file2: Bob Tuesday Carol Monday Ted Sunday ...
2
votes
3answers
119 views

How to filter some files out of my directory?

I have some files in my directory. They can be classified into two categories: the files' name pattern in class one are like 1000-24-1-7-1 that have five numbers separated by four dash; the files' ...
3
votes
1answer
14 views

Find repository names from gitolite info output

How do I extract the names from the gitolite info command output, for further piping into a script? I'm writing a migration script to migrate all my repositories from gitolite to a Gitlab server. ...
1
vote
2answers
69 views

Ping a host, check if alive or not, and send result to file via a shell script

To clean out my custom hosts file and remove dead domains on Windows I ping the hosts from domains.txt, and if I get a reply I add that host to result.txt: @echo off >result.txt ( for /f %%i ...
2
votes
2answers
51 views

Create variables and assign values via loop (bash)

Is there a way to create bash variables and assign them values via a loop? Something along the lines of: #!/bin/bash c=0 for file in $( ls ); do var"$c"="$file"; let c=$c+1; done EDIT: ...
0
votes
0answers
18 views

Bash Scripts arguments and G++ static and dynamic library generation [duplicate]

I have a library named matrix.cpp that is used by a program named test.cpp. Now, I want to write a BASH script which takes matrix.h and matrix.cpp as input and generates matrix.a and matrix.so ...
1
vote
1answer
17 views

need a detailed guide to start scripts and applications in xfce4

I am looking for a detailed explanation about where is the right place to start scripts applications during the boot process. It seems there is either confusion or not need for the detail I am looking ...
2
votes
2answers
57 views

Need to obtain Awk output in specific sequence

Data in file: 1234567-5678907 3456789-1234563 3456789-1234567 . . . . n Now I want the output in the below format: 1234567-5678907,3456789-1234563,3456789-1234563....n I have used below command ...
1
vote
1answer
73 views

Bash script won't work on current directory

I'm using Kali linux which is based on Debian and wrote an script to copy some files from where the script is based to a specified directory. But when I execute my script (called CopyFiles.sh), cp ...
-1
votes
0answers
19 views

useradd -c “Text” username does not work when reading data from a file [closed]

useradd -c "text" username works only from within a script when parameters are passed to the script on the command line, but when the parameters are read from a file, it doesn't work
2
votes
3answers
62 views

Command line options with argument in shell script

I have a script to get ldap user name, email and mobile number: #!/bin/bash echo -n "Enter Unix id > " read UNIXID ldapsearch -x "(cn=$UNIXID)" | awk '/givenName/||/mobile/||/mail/' Here is the ...
2
votes
1answer
37 views

ksh/bash Formatting Files through sed by cat file|sed command

I am new to unix platform, (Alternate Approaches can be discussed) I am trying to change the colors of content of a file conditionally. My file is: A B C D Value Value Value Value Value ...
0
votes
1answer
39 views

insert value from reference file

I have a daily csv file with thousands of rows. I have been asked to concatenate two columns, then insert a new column when a value in a given column matches a table from another file. Empty values ...
4
votes
2answers
190 views

Best and short way to run a program if another is not installed

I have this code: #!/bin/bash num=${1:-undefined} cmd=$(which {banner,echo} | head -n1) until [[ "$num" =~ ^[0-9]+$ ]]; do read -p "Type a number: " num done for ((num;num>=0;num--)); do ...
5
votes
4answers
236 views

Converting `for file in` to `find` so that my script can apply recursively

I've been working on my first bash script for some time now (I just started UNIX this week). I have this idea of running a bash script to check some conditions and using ffmpeg to convert all the ...