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

learn more… | top users | synonyms (2)

1
vote
0answers
52 views

File exists but errors with “mv: cannot stat: No such file or directory”

For some reason my script cannot copy or move files that exist. It comes up with the errors below. Can someone tell me why? cp: cannot stat '/mnt/sd/bbu/install/scratch/bin/.': No such file or ...
2
votes
4answers
52 views

Change dir from script without a “shell procedure” or “sourcing the script”

I know what I can make a shell procedure or source the script instead of running it to cd the shell I am using. What I want to know is there any way to cd the "parent shell" (not sure if that is the ...
1
vote
0answers
21 views

Piping to 'tee' commands prevents changes in environment variables

I have a csh script using which I modify certain environment variables and echo values of these environment variables from within this script. I source this from another script: source ...
6
votes
3answers
1k views

Executing mail command from inside a function causes a “fork bomb”

When I try to execute mail from inside a function in a bash script it creates something similar to a fork bomb. To clarify, this creates the issue: #!/bin/bash mail() { echo "Free of oxens" | ...
0
votes
1answer
37 views

How can I get many addresses from many trajectories with bash script without error?

I have many trajectories data. 500k. I try to get adresses of these coordinates. I use bash command in linux. #!/bin/bash filename="$1" while read -r line do uid=$(echo $line | cut -f1 -d,) ...
0
votes
1answer
22 views

cannot reload .profile from script

I am trying to reload .profile from the below script, but that doesn't work at all. #!/bin/ksh sed -i '/export rel=Rel1510_Linux/c\export rel=Rel1602_MX' ~/.profile source ~/.profile When I run ...
0
votes
1answer
40 views

bash script : How to backup /user/home?

I'm currently studying scripting and I need to create a script to backup the /user/home using .bz2. I need the script to verify if the user exists and if there was no user selected to backup. ...
3
votes
7answers
328 views

Check if shell variable contains an absolute path

I want to check if a shell variable contains an absolute path. I don't care if the path exists or not—if it doesn't I'm going to create it—but I do want to ensure that I'm dealing with an absolute ...
0
votes
1answer
29 views

How do I remove a . from the start of a Bash string and write the result to a variable? [duplicate]

I am presently writing a shell function and it would help me in writing it to be able to remove a . from the start of a folder name (changing the folder name from that of a hidden folder to that of a ...
1
vote
2answers
33 views

How do I keep command options from breaking other scripts executed within my command?

I have a bash shell script(my_script.sh) which runs a script(their_script) during execution. My script (my_script.sh) looks like this : THISDIR=`dirname $(readlink -f $0)` main() { cd $THISDIR ...
1
vote
2answers
43 views

How to select a row with latest date and time

I have a text file (space as delimiter) as shown below: Date Time---------OtherFields-------Source IP Destination IP 2014-11-24 12:58:59.290 1.2.3.4 ...
0
votes
0answers
51 views

sort files twice

I have a series of 300+ files that I need to sort twice, once by the date and a second time within that date by part of the filename. The only standard in the names is that ends with *mmddyyyy<time ...
1
vote
2answers
31 views

Cat all files in a folder including filename by using a for loop?

With this for loop which I execute directly in the shell, I am able to cat the contents of all files in a folder, with the value beside of it: $ for f in *; do echo -e "\t"$f"\n"; cat $f; done ...
1
vote
2answers
47 views

Getting list of corrupted file from folder and its sub folder

I have directory say folder which has sub-folders according to date like 01, 02, 03 and so on and each sub-folder has four directories called test1, test2, test3, test4 and all this directory contain ...
0
votes
1answer
24 views

Conditionals do not work in . ./script [closed]

I am trying to make a history file manipulations scripts. When I try to, for instance implement an incognito mode by running unset HISTFILE It doesn't work due to command running in new shell. ...
1
vote
3answers
132 views

Read a file line by line and if condition is met continue reading till next condition

I have a file foo.txt test qwe asd xca asdfarrf sxcad asdfa sdca dac dacqa ea sdcv asgfa sdcv ewq qwe a df fa vas fg fasdf eqw qwe aefawasd adfae asdfwe asdf era fbn tsgnjd nuydid hyhnydf gby asfga ...
2
votes
2answers
59 views

How to copy image files whose names don't end with their resolution size?

I have a folder with images in it and it is organized by year and month folders (ie. /2015/08/image.jpg). Whenever an image is added, it is also copied and resized like so: image-1024x768.jpg ...
0
votes
2answers
23 views

command to put hyphen in the second column if the space is given between a word [closed]

Suppose you have a file called test.txt with data like: you wel come how nice what do ing How can I add a hyphen in the second column if the space is given between a word?
2
votes
1answer
63 views

Tracking where the script stopped after timeout

I've got a shell script doing connection performance test, that I timeout if it takes too long. Upon timeout, it logs the results of a few commands so I can make myself an idea of the system status ...
1
vote
2answers
362 views

What is the meaning of a trailing “:” (colon) in *nix? [closed]

I am currently following a tutorial about shell scripting located here: http://www.cs.columbia.edu/~sauce/tutorial/ashell.html and I believe my script matches that one exactly. However, when I try to ...
0
votes
1answer
37 views

Identifying duplicate fields and REMOVE both with awk

Previously, I asked the question: Identifying duplicate fields and print both with awk. I have a file with multiple columns and wanted to identify lines where specific column values (cols 3-6) had ...
1
vote
2answers
48 views

How to execute a command randomly over a given time interval?

I am interested in a running a Unix command once randomly over a given time interval. For example, if the command is ls and my time interval is between noon and 2pm, how could I start a background ...
3
votes
2answers
33 views

Why builtin times doesn't work in pipeline?

I've the following sample script: #!/usr/bin/env bash sleep 5 printf "times cmd: " times printf "pipeline: " times | ( read user sys; echo $user; ) printf "head: " times | head -n1 printf "times cmd ...
1
vote
1answer
21 views

Pause (with read or similar) in xargs

I have a script that looks something like the following. find /path -type f | sed -re 'stuff' | xargs -Ix sh -c '{ echo "information about x" ./exe < x read }' My goal is to provide each ...
-3
votes
7answers
114 views

Is there a way to prevent sed from interpreting the replacement string? [closed]

If you want to replace a keyword with a string using sed, sed tries hard to interpret your replacement string. If the replacement string happens to have characters that sed considers special, like a ...
5
votes
6answers
181 views

Take grep value and output the count and the value together

I am trying to make a bash script that greps value and output the count and the value together Something like this grep -c 'Thenis' example.txt > example.lst But in that list file not only to ...
0
votes
2answers
42 views

Sort words in file

i've got some problems i'm not capable to overcome. I need to count the first let's say N words in a txt file. Then , i have to print them in decresing order, followed by the number of occurences.The ...
0
votes
0answers
33 views

Updating/compile sendmail script not working.

I have wrote a script to update sendmail and compile on unix system I put those lines if [ ! -e $CWD/src/$NAME-$VERSION.tar.gz.sig ] then echo "$NAME-$VERSION signatures missing" wget -c ...
1
vote
0answers
22 views

How to count nodes and get attribute value without using xpath

Currently I have a shell script like this: LOGIN=`curl 'https://www.ponta.jp/u/LWAS900/SLWAS900010.htm' -sS | grep '<input type="hidden" name\|<form\|</form'` for i in $(seq $(printf ...
3
votes
1answer
83 views

List of VBox Machines Help?

So, I'm writing up a bash script to list out the VM's on my host, so I can make sure they are fired up when the host machine restarts... no problem here... my issue is getting the list of the ...
1
vote
0answers
50 views

Error “dircolors: no SHELL environment variable, and no shell type option given”

Running Linux Mint 17.3 Cinnamon A while ago a created a script that changed the colors in the Terminal (to match a tutorial I was following) However if I open the terminal on another account, I get ...
1
vote
1answer
47 views

Exporting Variables and setting Global Variables in Bash [closed]

My objective is to create a list of variables that can be called or referenced by any test script that is being executed. There are a lot of test scripts on the system but the variables are ...
2
votes
3answers
50 views

How to wait for all spawned and backgrounded processes to finish in bash script

I've looked and looked and can't find a working solution to a bash script I'm trying to create to shut a process down and wait for it and spawned processes to finish. I'm still learning a lot of ...
1
vote
2answers
25 views

how to split long psql command in bash script over several lines

I have a long psql command to execute within a bash shell script, and I am wondering what the correct way is to split it across several lines? The standard Unix script 'split line' backslash ...
0
votes
1answer
22 views

i want to remove tag in xml when it is repeating multiple times

I want to comment particular tag with particular value from xml when it is repeating multiple times example: <t1> <t2>hi<t2/> <t1/> <t1> <t2>hello<t2/> ...
1
vote
0answers
15 views

Schedule (Cron) executing tasks based on bash scripts using CronniX

I'm still quite new you Mac and OS X but do have some background about other UNIX based systems, so please excuse for any misunderstandings. My goal is to implement a function that executes certain ...
2
votes
1answer
46 views

How do I turn entire stdin into a command line argument verbatim?

Attempt 1 xargs -I '{}' -0 -n 1 myprogram --arg '{}' --other-options But that does not preserve zero bytes. Also the program may run multiple times. But instead of failing in case of zero byte ...
1
vote
1answer
42 views

How to prevent bash from transforming arguments?

I am trying to use an argument of the script to find other files. The problem is that when i give the script the argument x.* in the command line, it is transformed into x.sh. Any ideas how i can get ...
1
vote
1answer
36 views

Running chown in bash script produces errors

I'm working on a script that downloads a file with bar:bar ownership, then changes the ownership to foo:server. So I wrote a side script(chown_test.sh) to implement the changing of the ownership via ...
1
vote
3answers
59 views

grep a awk string from a file and write to the other part of string file

My file, aaa,has 5 lines. 01_AAA-11-ID22 02_BBB-33-ID44 03_CCC-55-ID66 . . I tried to grep anything after underline from a file bigfile.txt for i in $(cat aaa) do A= $(awk -F '_' '{print $1}' $i) ...
1
vote
1answer
23 views

Long running script stops sending output to file

I have a script that I'm using to capture some status of the server at 10 second intervals. The script is as follows: for (( ; ; )) do /usr/local/apache/bin/apachectl fullstatus sleep 10 ...
1
vote
1answer
57 views

split file into multiple pieces

Problem: given a file samplein, it can be split up into multiple pieces as follows: $ cat samplein START Unix Linux START Solaris Aix SCO $ awk '/START/{x="F"++i;}{print > x}' samplein $ ls F* ...
4
votes
2answers
276 views

How to wait for the copying process (cp) to finish?

I want my RPi 2 (with MiniBian (a minimal version of Debian-based Raspbian OS) as its OS) to execute a script when it detects a USB flash memory is inserted. So this is what I have done: I created ...
0
votes
1answer
34 views

extract text from txt a file [duplicate]

I have a a file containing about 20 million sentences, how can I extract 2 million sentences out from it? I thought about using the split command like this "split -l 2000000 sub2016", but then it ...
0
votes
1answer
16 views

Getting error while using httpd -v command in script

I wrote a script to check the details of Web server's(RHEL) and save the output into a file. But the script is not passing the command httpd -v in the loop. Here is the script. #!/bin/bash for i in ...
0
votes
0answers
27 views

Process multiple csv Files in to one file with Format Arcsight would parse easily

I need some help in writing a script to process multiple csv files to a single csv file which is formated to be parsed by arcsight Here is the script so far, it is processing the first Two file ...
0
votes
1answer
39 views

How to replace single quotes and &apos in a file

I am trying to replace single quotes in a file and I used the command as sed /s/'//g filename and this command works fine but I have &apos character also in my file and which is not getting ...
1
vote
1answer
49 views

How to allow a bash shell script to loop for 3 retries before exiting (prompt for username/password)

I have a shell script that will ask for username and it will check against a list. if the name is inside the list, it will run another shell script but if the name cannot be found, it will prompt a ...
0
votes
1answer
30 views

Format the output of awk command

I have to format the output of the awk command which gets the input from a file Sample Input File 123 ABC 12 23 34 45 56 67 78 13 234 DEF 23 34 45 56 67 78 89 345 GHI 34 45 56 67 78 90 10 01 99 456 ...
-1
votes
1answer
26 views

cut command behaving differently when its output is “ * ” [duplicate]

I am trying to create a shell script, below is a part of which where i am trying to extract some value from a record in a file: tgt_val=`cat $file_name | grep "$string_name" | cut -d"|" -f$column_no` ...