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

learn more… | top users | synonyms (2)

0
votes
2answers
16 views

Using an ASCII file in mailx

I have a ASCII file with Unix user names. How can I mail this list to everyone on the list itself? I do not want to use an alias. I was trying to cat the file to a mailx string but it was not working. ...
0
votes
2answers
29 views

Getting error with sleep and argument in sh script

I'm doing something like this #!/bin/bash END=3 time_w = 1 for ((i=1;i<=END;i++)); do # do something sleep time_w done but I'm getting sleep: invalid time interval ‘time_w’
0
votes
2answers
24 views

How can I break out of a while loop, from within a nested case statement? [on hold]

In the script below - which prompts the user to confirm that they want to proceed with running a potentially bad script - when the user enters Y at the prompt - it will break out of the case block, ...
-1
votes
0answers
26 views

sh -eq: unary operator expected error

First off, I am very new to shell and coding in general. I'm trying to check disk size by the actual size, instead of just percentage. I found a piece of code that I have tried to alter a little bit ...
1
vote
3answers
33 views

Difference between sh -x and ./ for script execution

So I have a simple shell script. What is the difference between the two commands in execution? Is there a preferred way? $sh -x foobar.sh OR $ ./foobar.sh I found the script executed slower when ...
0
votes
1answer
22 views

How to ignore spaces in file path for bash select statement [duplicate]

I have the following Bash Script: #!/bin/bash cd ~/Library/Developer/CoreSimulator/Devices/; files=$(find . -name iaGambro_gambro.sql) select file in $files; do if [ -n "$files" ]; then ...
1
vote
1answer
23 views

finding a maximum and minimum file size along with their path in a directory

I want to find out the maximum, minimum and average file size along with their path. My code is: #!/bin/bash DIR="$1" echo "maximum file size:" du $DIR -h echo "average file size:" du $DIR -sbh ...
1
vote
4answers
114 views

How to maintain a specific number of processes running?

I'm trying to write a shell script for converting a lot of .wav files to .mp3. I use the "find" command to find them, then the "lame" command to convert. I can use a simple for loop for this but I ...
0
votes
2answers
38 views

No of files and directories in a particular directory in shell script

I am working on Linux and it's new to me. I created a shell script countfiledirs. I want to know the number of files and directories in a particular directory. My code is: #!/bin/bash echo "total ...
0
votes
1answer
36 views

How can I populate an array in Bash Shell script loop

cmdline> ls -la /.myScript.sh set index=0 set usrlist[index]="null" while read line do #Total lines read z=`echo $line| wc -l` lines=`expr ...
-1
votes
1answer
53 views

what is shell script? [on hold]

Is that some thing like a programming language? Which does provide this option(facility) by a program running on linux or basic program that comes with linux kernel?
0
votes
1answer
53 views

FOR loop not looping

I have the below script that uses 2 for loops. for some reason they loop is not looping #! /bin/ksh CURR_PATH='/main/nedcor/flexcube' cd $CURR_PATH for DIR1 in 'WIP' 'INPUT';do echo $DIR1 ...
3
votes
3answers
52 views

Shell script to move files if certain percentage of lines contain a certain string

I am working on a shell script to move files if certain percentage of the lines contain a certain string. I've got ~2000 files in a directory that each contain a single column of data. The number of ...
2
votes
1answer
53 views

Command for killing specific PID provided by previous command

Sometimes I need to kill a process (the reasons why are not important). And I know I can find that process with the following command: lsof -i :8080, being my candidate the last process in the output ...
4
votes
4answers
228 views

How can I safely get the version of ksh?

How can I safely get the version of ksh from within a ksh script? I have seen the following solutions: ksh --version echo ${.sh.version} echo $KSH_VERSION And if the circumstances are perfect, ...
2
votes
3answers
32 views

Create many files with random content

I am looking for a command to create multiple (thousands of) files containing at least 1KB of random data. For example, Name size file1.01 2K file2.02 3K file3.03 5K ...
0
votes
2answers
40 views

Remove line break in tex file

Remark: I'm working with .tex (TeX) file. In TeX code, line break does not affect the output. To produce a new paragraph we have to use the \par command. Some TeX editors interpret a blank line as ...
-1
votes
2answers
10 views

Shell Script: To extract a part of string from a file after a match is found

A script must be written to extract and return a string value from a file. This must be done only after a match is found in the file for the given pattern. Example: ...
1
vote
1answer
28 views

Passing variables to range patterns in awk

I'm trying to use range patterns in awk: grep -a volume somefile | awk '/^Apr 25 23:44:04*/,/^Apr 26 12:44:01*/ {print}' This works fine, but when I try to execute it by putting the date and time ...
2
votes
1answer
50 views

Filter a log file by month, date and time in bash

I'd like to fetch the data between Apr 24 10:00:00.000000 and Apr 25 24:00:00.999999 in the following log but I am not sure how to get this work: files/file1:Apr 22 02:47:00.663117 somedata ...
0
votes
1answer
24 views

Usage of '%' in the crontab [duplicate]

I am trying to add a cron job to perform an rsync from a remote server to a (Ubuntu12) local machine & create a log file. Below is the crontab-l 00 18 * * * rsync -a -v --delete -e ssh ...
-3
votes
0answers
29 views

using text browser on linux to display proxy information [on hold]

I have this question on my project , and can't how can be answer it , could you help me? how can store proxy information Permanently for a text mode browser such as links? I want steps , if you can. ...
0
votes
2answers
27 views

How to make the script automated to take password on its own?

I have a script that is doing sftp some files from one server to another, like inside the script script.ksh I have the below lines; sftp user@ip_address << EOF cd path put file1 bye EOF When ...
1
vote
1answer
44 views

Using single command to find NIC speed

Do you know a single line command to capture NIC speed of the primary interface of the server. For example, for eth0 Get hostname using uname -n Get its IP using nslookup `uname -n` Search for the ...
0
votes
1answer
49 views

How to avoid executing a command if a process doesn't exist

In a korn shell script, I am running expdp. I have made the script to where it can be reusable so if a later process fails, I can run it again without running the already completed steps. I am running ...
0
votes
2answers
37 views

init.d script not being run on boot

My script is not running on boot in a vagrant box under Ubuntu. My script looks like this - #!/bin/bash # /etc/init.d/mailcatcher ### BEGIN INIT INFO # Provides: scriptname # Required-Start: ...
0
votes
2answers
24 views

Tool for managing local development repositories [on hold]

I'm a web developer and I work with various languages and projects (who doesn't?). I've cloned many of these projects/repositories locally to various directories. Now, with dozens of projects cloned ...
0
votes
1answer
42 views

What's the best way to make a bash function in a script as a parameter when running via command line?

I'm fairly new to bash scripting, and wondered what's the simplest way to make bash script functions in a script as the parameter when run via command line? Example usage: ./myscript function1 ...
0
votes
2answers
39 views

set library path for current script [on hold]

How can I set the library path for the current script that's running? I mean I don't want to list a new path for the libraries in a textfile. I tried it using export LD_LIBRARY_PATH=$(pwd)/lib/ This ...
0
votes
2answers
37 views

How to grep from command line for theses multiple strings?

I need to run a command to grep one of these strings from command line as web host disabled account to run website from browser until virus files are removed and I managed to collect few strings that ...
1
vote
1answer
34 views

Script executes differently if run from udev

I'm having an issue with a script that seems really weird; it appears to stop executing prematurely when run from udev, but not when I run it manually from the command line. I've tried troubleshooting ...
0
votes
1answer
31 views

find statement inside backticks not recognised inside shell script

I wrote the below small shell script. However when i run it am getting the error ctrlM_chk_input_file.sh[5]: find: not found but I thought the backtics will make the find statement to be run as a ...
0
votes
0answers
22 views

Sending a HTML file (with images) as email body using command line

This seems like a basic question and there are variations of it. I have a ONE-COLUMN html file (let us call it status.html). I would like to send this file which has a few images as the BODY of an ...
1
vote
2answers
65 views

In Linux 'top' command, is there any way to keep track of values?

I'm using the Linux "top" command to monitor %CPU of particular process. As the values keep on changing every few seconds, is there any way to keep track of values in a separate file or as a graphical ...
0
votes
0answers
51 views

Script to rename files [closed]

I was fixing my freenas movies and subtitles files and realized a script would help a lot. The point is I must replace the files in some directory to something like S01E02.avi, for example. In order ...
0
votes
2answers
51 views

How to extract unknown arguments within a shell script?

I have a shell script that accepts a variety of options, some with arguments, some without, some short, some long. It should handle some of these options itself and pass on the rest it does not know ...
1
vote
2answers
64 views

How to loop over users?

How can I loop over all users in a shell script? I am writing a shell script to perform cleanup on a system. And if the script is run as root, I want to perform the requested actions in all users' ...
0
votes
1answer
24 views

Retrieving prompt information in ksh?

If there is a prompt being read for a value such as: #!/bin/ksh echo "What is your name?" read name username=$name rcmd machine1 grep $username /path/locnames >> namefile rcmd machine1 cat ...
3
votes
1answer
148 views

prevent a command from sending both stdout & stderr to any terminal or file [duplicate]

I would like to prevent my program from sending stdout and stderr to any terminals, files or devices. For this, I have three command crossing my mind, but I cannot distinguish their differences. Could ...
0
votes
0answers
38 views

How do I write a script for testing username/password? [duplicate]

I have about 500+ hosts I need to test a username/password combo to make sure there aren't any false positives in the list. I just need to make sure I can login and log out, no need to run anything ...
1
vote
3answers
78 views

Using sed to consolidate diff output

I have this output as a result of comparing files with diff: < IF-Name :STRING: "lns-wall-01-t2" Index:Gge32: 260 --- > IF-Name :STRING: "lns-wall-01-t2" Index:Gge32: 25 I need ...
2
votes
2answers
57 views

Executable script can't run directly from desktop in Arch Linux

Before, I was using Linux Mint and I can run bash script directly from desktop just with chmod the script to executable. For example, I have a script like this: #!/bin/bash VBoxSDL --startvm ...
8
votes
1answer
211 views

Bash wildcard to match exactly n characters

Is there a wildcard in bash to match exactly 5 characters, shortening a pattern like ?????
0
votes
1answer
22 views

Dialog radiolist using dynamicaly defined array of choices

Following my previous question, I have write the following MWE to create a simple file selector by date filesArr=( $(ls -1rt ??????????_?) ) nfiles=${#filesArr[@]} iLastFile=$[nfiles-1] choiceArr=( ) ...
5
votes
3answers
277 views

How can I make a script take multiple arguments?

This is a very simple script #!/usr/local/bin/bash set -e if [ "$#" -lt 1 ] then echo "Please insert at least one argument" exit else echo -e "\c" fi if [ -h "$1" ] then echo "$1 is a ...
3
votes
2answers
297 views

How to print out only the script name?

[username@notebook ~]$ cat foo.sh #!/bin/bash echo "$0" [username@notebook ~]$ ./foo.sh ./foo.sh [username@notebook ~]$ Question: How can I output the "foo.sh"? No matter how was it executed.
0
votes
2answers
29 views

Add some text while output to file

Assume I have this command: ./clang-$j.out >> clang-result.txt and the each output for clang-$j.out is a fixed-length hash value (each program per line), however, I want to distinguish them by ...
0
votes
0answers
26 views

compare dynamic file [closed]

I have a list of file that will be updated each hour and the name given to these file is according to the date and the hour for example: list_hour_date.txt list_9_20042015.txt list_10_20042015.txt ...
1
vote
1answer
32 views

How to run a shell script (bash) on a chromebook?

I have a shell script and I need to run it in order to connect to a remote ubuntu linux machine having encrypted HDD, in order to enter the passphrase. There's a shell script for this, but I have a ...
1
vote
1answer
22 views

Need a shell script for copying files that have long and out of capacity names

I have a directory on a NTFS file system which contains files with short and long names, I entered copy command for that directory to be copied on a Ext2 file system, files with short names copied ...