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

learn more… | top users | synonyms (2)

0
votes
0answers
3 views

Conditional file and directory installation in Debian Packages

Is it possible to create a binary Debian package with conditional files and directories installation (e.g. installation of an init script in /etc/init.d/ after being confirmed by user)?
0
votes
0answers
9 views

How to make sure the same string doesn't appear next to itself in an array?

I'm making a Rubik's Cube scramble generator, and the turns can't be side by side or else it's useless. I'm trying to stop it from doing the following: Displaying the same string twice, i.e R2 R2 ...
2
votes
0answers
40 views

To count number of matches in a mega string quickly

I have big text-data without spaces and without other rows in one line. In reality, the streams are 0.2 Gb/s, similar situation here, but in this task, counting occurrences which is more challenging ...
0
votes
0answers
22 views

How to source a config file without print the results out?

In the past, I'm using bash consistently, because it's everywhere. But recently I'd like to try zsh, and don't want to give up updating my .bashrc file( It was rsync to all my servers). So, in my ...
0
votes
0answers
26 views

This code isn't working. (Trying to declare array values in a for loop and do math functions on them)

I was again bored and looked up a list of programs to make in bash, and I'm trying to make a CC (credit card) validator. I had to split the characters into an array to do the validation, and I think I ...
1
vote
0answers
20 views

Exceeding paste's length limits in resulting line? [on hold]

I'm in a situation where I am extracting files using Informatica.My problem is that in extreme cases I'm exceeding the maximum length for a resulting line for the header line. I'm on Oracle. What I ...
3
votes
1answer
49 views

Script started as `source` or `executable`?

Can we determine inside the very script whether it started as source (.) or executable (shebang or something alike)?
-1
votes
1answer
48 views

Pass string value to date in Unix

mm="27 Jun 2011" dd=$(date -d'27 Jun 2011' +%Y%m%d) echo $dd I want to use value of mm in second line. When i tried like below dd=$(date -d'$mm' +%Y%m%d) It is giving error.
-1
votes
1answer
29 views

shell script not running using crontab

This is my script mboxutil -l > n.txt sed 's/^.*user//' n.txt > n1.txt cat n1.txt | sed 's/^.//' > n2.txt sed 's/\/.*//' n2.txt > dss_list.txt rm -f n.txt rm -f n1.txt rm -f n2.txt sed ...
0
votes
1answer
34 views

How to extract particular fields from lines using shell commands?

File1: 27/07/2014 10.10.03 Breaker1 was closed by Mr. A.Basu Spectrum ui6dms 29/07/2014 04.50.53 Breaker1 was opened by Mr. D.Gupta Spectrum ui6dms and one note added 30/08/2014 03.20.01 EarthSwitch ...
0
votes
2answers
65 views

What is wrong with the code? [on hold]

#!/bin/bash for ((i=1 ;i<=3;i++)) do echo "Enter gallon used(gal):" read gal echo "Enter Miles Obtained(mil):" read mil mileage=`echo $mil / $gal |bc` echo "scale=4; $mileage " | bc c=`echo $c + ...
0
votes
3answers
46 views

Bash: increment a variable in a while loop?

Bash newbie here! I have a bash script that for each file in a set, greps each line in the file for a string. Then it splits the line on commas, converts the 7th element to a float, and increments a ...
6
votes
3answers
261 views

Should I use a slash at the end of path variables in shell script or not? [on hold]

Today when writing my shell script. A question suddenly comes to my mind. Since cd /target_dir and cd /target_dir/ both works. Should I add a slash at the end of my path variables in a shell script? ...
-3
votes
1answer
38 views

sed/awk - replace first occurance of a string with array of strings [on hold]

I want to find the first occurrence of a word and replace it by 3 strings using sed/awk. for example , I have the below entry in my /etc/hosts file 10.4.16.11 dispatch1 10.4.16.12 dispatch2 ...
2
votes
3answers
201 views

Am I using a while loop wrong?

I found a list of projects to do, and one of them was something that generates amounts of change. I made this code: getamt() { echo "Enter amount of money." read amount echo "OK." } change() { ...
0
votes
2answers
39 views

validate record count in header

I am trying to write a script that should verify total detail records equal to the Record_count in header record, If not throw an error sample data 0001 HD SAP _AP Distribution 20150615 131723 ...
0
votes
1answer
18 views

Substituting the value with spaces for a variable in bash script - the correct way

I have a compilation script that can compile the program with and without the debug symbols. I want to ask via bash prompt ( read ) the user to choose whether he wants a debug version or not with ...
0
votes
1answer
23 views

Export mysql to remote server using one SSH session

I've come across a situation where I had to create a utilitary shell script that would be executed in many servers from different regions. The objective is to dump the local mysql database, copy it to ...
-2
votes
1answer
38 views

Comma and newline replaced with comma [duplicate]

How can I find the solution to replace ":" and newline with comma, and to remove "./" below is the sample format. ls -lRm ./www.toncemoy.com: www_ttoncemly_com, www_ttoncely_com, www_toncethly_com, ...
0
votes
0answers
52 views

comma and newline to be replaced with comma [on hold]

Can anyone help me finding the solution to replace comma and newline with comma, below is the sample format. www_sngforadultadhd_com, www_scegforadultadhd_com, www_scegforadultadhd_com, ...
4
votes
4answers
99 views

How to Check the existence of multiple files in a directory and zip the same

I am facing an issue while checking the existence of files ending with the same string/pattern. The file names might be as follows abs_123.unl xyz_123.unl Currently my code is as below and working ...
1
vote
1answer
43 views

Syntax error at a semicolon in a shell script

The one liner command will be longer but this is the part that is throwing the error. for user in natural1 ; do cat <<EOT >> /home/$user/public_html/.htaccess <FilesMatch ...
1
vote
1answer
26 views

Silent installation of shell script using bash file [on hold]

I have a setup file for Linux which is in shell script format. I'm trying to perform a silent installation by writing a bash script. When I directly access the script I'm unable to suppress the setup ...
3
votes
1answer
169 views

Approximating a floating point number with correct rounding off

How can I approximate a floating point number using shell-script (say, up to 4 digits after the decimal point)? I have two examples: A=1.2345678 and B=1.2345678E-05. So I would like to get ...
-3
votes
0answers
53 views

Bash Shell - Grep a line from a file - append from an entered variable and query that line?

I would like to grep a line from a txt file use that line and append the variable used "entered from the user. Get the output of the grep add variable with a space and then query that line. Any ...
1
vote
6answers
162 views

Hiding Password in Shell Scripts

How can I hide a password in shell scripts? There are a number of scripts that are accessing database. If we open the script others also aware the username and password. So if anyone knows how to hide ...
0
votes
3answers
55 views

Creating a script that runs a simple command for all files in a directory

I need to use the text-based browser Lynx to dump 1000s of html files into text files, with the same filename. For any given filename.html the command is lynx filename.html --force-html --dump > ...
0
votes
1answer
43 views

Practical usage of “shift” shell builtin command?

I checked the /usr/bin/ssh-copy-id(part of openssh-client package at least under Debian) shell-script and it contains following if-statement: if [ "-i" = "$1" ]; then shift # check if we have 2 ...
0
votes
2answers
31 views

generate alphanumeric string from pattern

I want to generate host names for example from my patter like this: inc-[tnc][app|web][1-10] where it should output like below: inc-tapp1 inc-tapp2 . . inc-tapp10 inc-napp1 . . inc-capp10 inc-tweb1 . ...
1
vote
1answer
51 views

Can someone explain this tail + line to me?

I'm looking through some of the scripts that are on the servers and came across an 80MB shell script. Naturally curious I decided to look in there and came across this line: tail +4802 $0 | zcat - | ...
-1
votes
2answers
35 views

Enter a variable into a command in bash

My question should be simple for you guys. I am writing a simple script that runs a command but the file it would need is always different. Is there a way for it to ask: "Where is the file?" And ...
1
vote
2answers
53 views

How do i search for certain sections of a file and then extract only relevant information within that section?

So I have a text file that is a server report and has about 1000 lines of information in it. I'm trying to write a script that can search the report for only certain pieces of information I'm looking ...
0
votes
1answer
32 views

Is it bad practice to put sections of main code in functions? [closed]

I didn't like the way the code that I had looked, so I compressed all of the main 'blocks' into functions. (This would also prevent the code from running if an error was present.) I don't know if this ...
-1
votes
0answers
17 views

sql query not returning records from DB having timestamp in where clause in shell scripting [closed]

I am trying to get the records from DB using shell script having timestamp in the where clause, but the query is not returning any records. Its shows as "no records found". But the same query is ...
9
votes
6answers
1k views

Is it possible to substitute “then” with brackets?

I first learned how to code in a C language, and using if ( code ) then code fi makes it really hard for me to read my code (don't ask why). Is there a substitute for then? Something like this: ...
-3
votes
2answers
39 views

Transform text records using only a “for” loop

I have an input file that is text, consisting of lines that look like: 352|C|PAID|7036|VOICE|01-FEB-12 I need to split each line into fields at the | (vertical bar) characters and output each field ...
-1
votes
2answers
15 views

OpenDNS automatic diagnostic

I've contacted OpenDNS support because advertising are not filtered on this site http://www.backpackerboard.co.nz/ They asked me to read this manual instructions ...
0
votes
1answer
17 views

Comparing Oracle version in bash script

I'm trying to create a bash script to install an application that requires Oracle 11g client. How can I read in the version info within the bash script? sqlplus when run in Putty spits out the ...
0
votes
0answers
22 views

Run a command stored in a variable [duplicate]

I am working on updating some scripts we have used previously ( on RHEL) to work for a new flavor of Linux (ESX). As I am modifying the script, I wanted to add user feedback as well as some other ...
0
votes
1answer
27 views

How to clear log files periodically

Hi I am new to Shell script. i want to clear log files in a directory basing on the dates. I have managed to gather this code: DIR1='/home/u01/app/oracle/servers/DIR1/logs' ...
1
vote
2answers
39 views

How can I delete <93> <94> symbols in file? It is equivalent “ ”

I copied text from a PDF file in bash - vi and I get lines like this: echo <93>The Hypotenuse is $hypotenuse<94> I tried to change that in vi by: s/<93>/"/g But: E486: ...
4
votes
6answers
187 views

Loop in text files shell script

I have a list of files in one directory and a set of jpegs corresponding to each file in another directory. I need to loop over all files, and for each file name, determine the target directory. For ...
0
votes
1answer
22 views

A script to install OpenVPN & modify iptables?

I d like to automatize the install/config of OpenVPN on my client machines. Roughly, it should looks like : - apt-get openvpn - cp, edit, .... - modify iptables. Is it possible in one script ? or am ...
-3
votes
0answers
27 views

Add '/' at the end of line without directing to a file in unix / shell scripting [closed]

Is it possible to add '/' at the end of a line having the pattern SUCCESS? Without directing the output to text file. E.g. When I execute the script the output may have "SUCCESS" pattern. If then I ...
0
votes
1answer
36 views

How remove duplicates in same file and with if condition?

INPUT FILE: has all these values without header: customer ID, code, start_date, end_date 124343, DCW, 2015-07-06, 2016-08-03 235432, ABC, 2015-04-26, NULL 235432, ABC, ...
2
votes
4answers
120 views

How to see if there are any matching characters in a string?

I'm making a card hand generator, and I want it to note if a specific hand is generated, like a three of a kind or a full house. I was trying to figure out how to do it, and I thought of using grep on ...
0
votes
1answer
15 views

Creating service in SLES / SUSE 11 SP3

I have a python script that works very well executed from a (remote) console like this : sudo /srv/web-asset-server-master/python server.py The problem is, that it only lives as long as the console ...
-1
votes
1answer
83 views

mv command does not work in shell script [closed]

I want to rename a folder with a bash-script. I don't know why this command is not working in a shell script, but directly in the terminal is working without problems. ...some code... ...
-4
votes
3answers
34 views

find and replace strings with another string command line

I have a Ad-blocking hosts file with 0.0.0.0 IPs pointing to URLs. How to replace 0.0.0.0 with 127.0.0.1 command line without any visual text editor ? Manually doing this with nano , vi etc. is ...
0
votes
2answers
30 views

Where should startup scripts for a specific user be installed?

I have one script that will run when a specific user logs in. Where should this script and its assets be placed? I was planning to put it in /usr or /bin or /var, but I was wondering if there's a ...