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

learn more… | top users | synonyms (2)

2
votes
2answers
40 views

Grouping lines into heterogeneous subsets

I have file with n lines.  (Each line refers to a “question”, and therefore they are labeled Q.1, Q.2, Q.3, ..., Q.n.)  Each line (question) has a “Marks” attribute, which has the value 2, 3, 4, 5, or ...
0
votes
0answers
31 views

Storage allocator out of space error on unix shell script

While running the script called abc.sh, following errors are thrown. abc.sh: line 226: storage allocator out of space on 64946176 byte request ( region 64329285632 segments 1981 busy ...
0
votes
2answers
32 views

BASH script to search for files in folders of 4 digits and older than 7 days

#!/bin/bash unset result result=$(find /home -path "$HOME/TestDir/[0-9][0-9][0-9][0-9]/test*" -mtime -7 -print -delete 2>/dev/null) [ "$result" ] || echo "There are no recovery files older than 7 ...
2
votes
2answers
44 views

find closest matching folder

What is the best way to sort the results of $ find . -name scripts -type d by the occurrences of '/' and then choose the first result. I want to create a function that would cd down to a common ...
0
votes
1answer
26 views

How to create a script to send e-mail by telnet?

I want to create a sh file to send e-mail by telnet. Something like this: read -p "from: " from read -p "from (friendly name): " fromf read -p "dest: " dest read -p "dest (friendly name): " destf ...
1
vote
1answer
26 views

Loop over lines of file, partition file and classify each partition

In the following I've put up my code for iterating over lines of a file in order to collect data within a segment from the file in following fashion: Illustration for understanding procedure: segL ...
0
votes
1answer
39 views

bash script locked at if statement when executed

I am no expert with bash scripting. I am trying to understand why a bash script seems to stop its execution at an if statement. I have added echo statements in the scripts. I have a first batch ...
1
vote
3answers
56 views

Pipe output of one command to two others [duplicate]

I need to pipe the output of one command to two other commands. cat filename.txt | tail -n 1 cat filename.txt | wc -l Since the file is huge I want to avoid reading it twice. I checked tee command ...
6
votes
4answers
287 views

Bash, execute command after invoking a new shell

I am trying to make a script like this: #!/bin/bash sudo -s something... When I execute it, I get a new shell but something is executed only when I exit the shell created by sudo -s, not inside it. ...
0
votes
4answers
95 views

How to extract column name (header) from a CSV file which contains the max value in a row?

I am trying to extract the column name with the maximum value in each row using bash script i.e., the column header value or the value from the same column in the first row. I am using the following ...
0
votes
2answers
24 views

sum of all packets in pcap files

I'm trying to make a simple bash script to calculate packets captured in pcap files, I used tcpdump to get packets in each pcap file and add them using a bash script but it doesnt seem to work. ...
2
votes
2answers
97 views

Merge two-columns files into one file

I have a bunch of files (file1, file2,file3, ...) with two columns. For example, file1 looks like: 0.12 0 0.32 0 0.42 1 0.23 0 and file2 looks like: 0.34 1 0.55 1 0.31 1 0.99 0 I wonder how to ...
0
votes
1answer
44 views

Save command string into bash variable

I'm running a command like so, with the $OUTPUT variable saving the results of the command. But I also want to save the command itself to a variable for inclusion in a status email. OUTPUT=$(php -f ...
0
votes
1answer
24 views

Loop commands to network daemon?

I'd like to feed a network daemon using a loop! To be more specific: There is a network daemon listening on localhost:portx. The daemon expects me to guess a PIN between 0000 - 9999. I want to use ...
-1
votes
2answers
38 views

Create shell script to remove certain files from specified directories

I am looking to create a simple script that does the following: cd /specified/directory cd into child directory only if it has a 4 digit name e.g 1234 rm -r all files that begin with letter P rm -r ...
0
votes
1answer
49 views

Bash script strange behavior - script does not act as manual commands

So, this is strange. When I manually run commands it all works fine, but when I run a script with identical commands, I get strange error output. This is what I run: lxc list; for elem in ...
2
votes
0answers
29 views

Sed is unable to copy temporary file to original file [duplicate]

My aim is to edit the file(Whose owner is user1) using script where user2 don't have permission to directly edit the file but it should be edited when executed through script by user2, so I set SUID ...
-1
votes
1answer
46 views

How to rename or delete an alias permanently from system?

I have created one alias in my system, printf "%s\n" "alias shh='sqlplus hfdora/hfdora@hfd2" >> ~/.kshrc Now, I want to change the alias name from shh2 to shh Also, how to delete other ...
2
votes
2answers
32 views

Call a script for another script, but don't exit the parent if the child calls exit

first.sh: #! /bin/ksh echo "prova" . ./second.sh echo "ho lanciato il secondo" . ./third.sh echo "ho lanciato il terzo" second.sh: echo "sono nel secondo script" dosomething1 exit $? If ...
3
votes
4answers
385 views

Add path to $PATH if not already in $PATH [duplicate]

I need to add a path in a bash script, but it may be executed several times: export PATH=${OPENSHIFT_HOMEDIR}/app-root/runtime/bin/:${PATH} I don't want that path to be added over and over. How can ...
0
votes
1answer
56 views

sftp to use password stored in a parameter file

Is it possible to to connect two server through sftp with a batch of commands and where the authenticating password needs to be read from a file(where it is stored previously).I am new in UNIX world , ...
0
votes
1answer
10 views

Command Run Differently Depending on How Logged In?

Is there a way to have one command run differently, depending on the manner in which one is logged into the session launching it? Basically, we have a command that when run, launches vim to display ...
1
vote
2answers
47 views

Returning an variable from a function

I have the Linux script from bellow. I can get to return from the method decrypt nothing in order to unzip a file. The method decrypt sends a string with the name of a zip file. Please give some ...
1
vote
3answers
45 views

How can I un-write protect file made by tee?

I have a small program and I want to ensure that it works on both write protected files and un-write protected files. So, instead of using echo $text > $file or echo $text >> $file, I am ...
-9
votes
1answer
61 views

replace the the first line of all .sh files in a folder

Create list of all .sh files in current folder. Check first line of each file in this list and if file starts with #!/bin/sh then replace that with #!/bin/bash. Only modify files that have #!/bin/sh, ...
-5
votes
1answer
63 views

Find the number of files with sizes

Find the number of files with sizes > 100KB in /, /bin, /usr, /usr/bin and /usr/sbin directories and output them in a two column format with the name of the directory and the number of files.
1
vote
3answers
43 views

permissions of script to change permissions?

I have a VMWare VM that directly accesses some disks. In order to run (without running vmware as su which has its own problems) I need to change the ownership of the devices. I've done this manually ...
0
votes
0answers
5 views

Find MAPISend syntax and Replace with BLAT syntax

My MAPISend code seems to have kicked the bucket so now I am trying to replace over 1,500 MAPISend lines with BLAT. Is there a way to search through my scripts and find the MAPISend syntax: ...
2
votes
2answers
38 views

Embed “cat file” in CURL data

I would like to cat the contents of a file.txt and use this as part of the --data field in my curl query. I tried: curl ... --data '{ "file_content":[" $(cat file.txt) ", ...]}"' ... but that ...
1
vote
2answers
104 views

Execute CURL command only once in script?

To explain a little, I am currently monitoring a folder for any changes and when changes are detected it simply uploads the detected files to my server via rsync. This is working without any issues : ...
1
vote
2answers
37 views

Else not Executing

In my script, I transform data to a more readable format. But I am having an issue. If no arguments are typed, just the script, I want it to come back "Please enter a filename" which I have done. But ...
1
vote
2answers
59 views

where I can modify the below shell script?

This is my input: #!/bin/bash #Example of menu programs clear echo "*******************" echo "1.Date" echo "2.List of users" echo "3.Open a file" echo "4.delete a file" echo "5.Exit" echo "Enter a ...
0
votes
0answers
17 views

What does a hash key preceded by an exclamation key (!#)mean? [migrated]

See the following script from scala tutorial, What does the !# mean? #!/bin/sh exec scala "$0" "$@" !# object HelloWorld extends App { println("Hello, world!") } HelloWorld.main(args)
1
vote
2answers
103 views

Remove lines from CSV file if the second column is in a word list

I have found a long list of free email providers that I want to remove from my email lists - https://gist.github.com/tbrianjones/5992856 Below are two commands I currently use that do the same job ...
3
votes
1answer
43 views

Generate a large number of the same byte [duplicate]

I'm generating a binary file as test data for a piece of software. The test data should consist of a long array of the same byte. If it was a zero byte I would use /dev/zero. Is there a command to ...
1
vote
3answers
51 views

script for copying directories with particular increment

I have directories which are named as 0.1, 0.15,0.2, 0.25, 0.3,0.35 and so on. Now I want to copy directories at particular increments say of 0.1 together to a separate directory. Say directories ...
0
votes
2answers
70 views

Shell Script: Sending input to background process

I am using the following script to watch a folder, and if the size changes and a file doesn't exist, it runs a script. #!/usr/bin/sh SCRIPT="dim_import/xdir" while true; do size=$(du -s ...
0
votes
1answer
18 views

Determine the tmux session a shell session belongs to?

tmux provides a number of commands in the shell such as rename-session which operate on the session that the invoking shell belongs to. It also provides commands like list-clients which list out the ...
0
votes
3answers
86 views

How to rename all files with special characters and spaces in a directory?

How can i rename all the files in a specific directory where the files contains blanks spaces and special characters ($ and @) in their names? I tried the rename command as follows to replace all the ...
1
vote
4answers
48 views

How to move all files (excluding sub-directories) from one directory to another?

How do you move all the files (excluding sub-directories) from one directory to another. I'd prefer if the solution used just basic shell scripting.
2
votes
1answer
51 views

SSH command not exiting properly [closed]

I wrote a script that SSH to remote servers in loop and run a command, it gets hung after running on last server.Here is my loop script - cat server | while read serName do ...
1
vote
1answer
54 views

How to make awk work in a while loop

input.txt: /usr/dir1/file1 /usr/dir1/file2 /usr/dir2/file4 /usr/dir3/file5 Script: cat input.txt |while read FILENAME do nawk '{print $1}' ${FILENAME} >> output.txt done Expected output: all ...
0
votes
1answer
62 views

load bash comands from file one per line and execute them for each file in a directory

I'm trying to write a bash queue which will be able to load command set from a file and then execute each over set of files. prepared file should serve as a template for execution in manual bash ...
3
votes
1answer
39 views

Condition on finding a file

I'm trying to write a script which looks for a file and if it is found, saves the full path to a variable. Current version: if [[ -n FOUND_PATH=$(find "$PATH" -name "file.exe") ]]; then echo ...
0
votes
0answers
15 views

Accessing HTML pages through command line for scripting [duplicate]

There is a web page that I usually do the same thing over and over on. Click a button, enter some text and that's it. Is there any program that allows me to interface with a webpage with a couple of ...
3
votes
2answers
30 views

Setting variable with default value behaves differently when preceding a command?

Setting a variable with a fallback default value works...as long as we're using the variable in a subsequent command: $ unset APP_ENV $ echo $APP_ENV $ APP_ENV="${APP_ENV:-production}"; echo ...
1
vote
2answers
45 views

Remove x lines before and y lines after nth line (which matches a pattern) in a file

I'm trying to remove a four line block from a text file if the second line matches the Regex N+. The text file is composed of many repeating 4 line formats, ie: @HEADER1 ACTGCNNNT + 583@#!NMY ...
0
votes
4answers
53 views

Excluding specifics lines from being redirected [closed]

Let's say I am executing a script like this : /a/b/c/script.sh >> abc.log This will mean that all the contents/execution of script will be re-directed to abc.log. If I want a particular line ...
0
votes
1answer
32 views

Redirect stdin for multiple shell functions [closed]

I'm surprised nobody has asked this before - maybe I'm just that dumb? How to I force this script to do what I intended? #!/bin/bash function One() { IFS='' read -r -n1 CHAR echo "One: '$CHAR'" ...
0
votes
1answer
30 views

Calculate swap values dynamically

Can someone please let me know if the below should work as i am not sure and getting error? Just to let you know that i am using in one of my nagios script ## GET SWAP Warning and Critical values ...