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

learn more… | top users | synonyms (2)

0
votes
2answers
34 views

Help with passing parameters to a file and fetching the credentials

I have developed a shell script which takes schema id and password as parameter to login into database using sqlplus,runs a query and mails the result. Below is the code snippet: #!/bin/sh #Two ...
0
votes
1answer
31 views

Iterating over an array in a shell script

I want to write code that reads a list of packages from an array and tells me whether the corresponding RPM is installed: ARRAY=( pkg-config python python-devel python-libs readline renderproto ...
2
votes
3answers
98 views

add space 5 times at the beginning of each line in a text file

I am looking for a command line or bash script that would add space 5 times before the beginning of each line in a file. for example: abc after adding spaces 5 times abc
-1
votes
1answer
36 views

Loop is not working as it should [closed]

Am i missing something, because this loop sometimes is not working as it should? #!/bin/bash Data="/path/to/data.txt" while true do if [ -f "$Data" ]; then rows=$(tail -n +1 "$Data" | wc ...
0
votes
2answers
49 views

Dealing with if statement

I have enhanced the code from the question I posted before: My code is: DIR="$1" if [ -e "$DIR" ] then echo -n "total directories:" ; find $DIR -type d | wc -l echo -n "total files:" ...
2
votes
1answer
101 views

how to deal with arguments when executing a script

how to deal with arguments when executing a script my code is: #!/bin/bash DIR="$1" if [ DIR eq $1 ] then echo -n "total directories:" ; find $DIR -type d | wc -l echo -n "total files:" ; ...
0
votes
2answers
41 views

Order the output using sed [duplicate]

I need your help using sed. I have this output after executing diff: < #R1#Number = Gauge32: 258 Name = STRING: "TATA" --- > #R1#Number = Gauge32: 280 Name = STRING: "TATA" I need to ...
0
votes
2answers
37 views

displaying output in a single line

How to display output in a sinlge line. My code is: echo "total directories:" && find $DIR -type d | wc -l echo "total files:" && find $DIR -type f | wc -l output displays as ...
2
votes
1answer
127 views

rm -rf: cannot remove `/opt/jetty': Directory not empty

I have a script using the following command to remove a folder: ssh -q root@hostname sh -c 'rm -rf /opt/jetty/' Most of the times it works fine, but occasionally I get this message: rm: cannot ...
0
votes
1answer
71 views

Shell Script Help - Automatically assign users to group

Recently, I have just started to learn linux and I am currently trying to make a shell script that can automate the task of creating user accounts, assigning them passwords and then assigning them to ...
0
votes
3answers
39 views

Loop for snmpwalk in bash

I have an issue in my output using snmpwalk so i'm trying in this script: var=`snmpwalk -v2c -c private ${ip} .1.1.1.6` echo "${hostname}=>${var}" to have this output: R1=>Gauge32: 240 ...
0
votes
2answers
27 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
34 views

Getting error with sleep and argument in sh script [closed]

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
43 views

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

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
vote
3answers
62 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
33 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
2answers
109 views

How to find 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. Incase a directory holds similar file sile (say 15kb,15kb) it should display the path of both files and its files ...
3
votes
4answers
136 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
71 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
52 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
59 views

what is shell script? [closed]

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
60 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
86 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
64 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 ...
5
votes
5answers
312 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, ...
3
votes
3answers
54 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
48 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
19 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
33 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
59 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
35 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 ...
0
votes
2answers
37 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
51 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
53 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
125 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
27 views

Tool for managing local development repositories [closed]

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
49 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
45 views

set library path for current script [closed]

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
43 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
41 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
32 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
1answer
56 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
77 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
2answers
58 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 ...
3
votes
2answers
97 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
27 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
153 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
93 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
86 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 ...