The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks. Use this tag for questions applying to /bin/sh and most compatible shells (ash, bash, ksh, zsh, …).

learn more… | top users | synonyms (1)

1
vote
1answer
35 views

Not getting the desired output for echo command [duplicate]

Below is my script. #!/bin/bash SERVERS="sl20rht00-t" #SERVERS="shcbrht01-t" USR="adm-dt-c" for host in $SERVERS do ssh -tt $USR@$host 'sudo cp /etc/sudoers /Backups/sudoers_11thmarch2015; sudo cp ...
1
vote
1answer
96 views

permission issues while doing ssh setup in cygwin

I'm trying to setup ssh-host in cygwin. Getting the below error: *** Warning: The permissions on the directory /var are not correct. *** Warning: They must match the regexp d..x..x..[xt] *** ERROR: ...
3
votes
2answers
137 views

Meaning of `cat /dev/null > file`

In a document created by a former coworker there is this command: cat /dev/null > /var/spool/mail/root It says next to it that it will clean out mailbox. Can someone please explain how/why ...
-2
votes
2answers
31 views

grep to get all the getters from a java file

I have a java file called Friends.java . There are 5 variables and each variable has its own getter. Assume that all the functions below follow standard java standard, i.e public methodName(){ //Some ...
5
votes
4answers
374 views

list graphical processes from terminal

Do no confuse the question here with how to list processes graphically, that is not what I am asking. In the Terminal, how can i see which processes have a GUI? as in things like firefox, vlc, ...
1
vote
1answer
56 views

Shell : while read line nested

I've two documents: doc1.lst and doc 2.lst I want to take the content of each line and put it as parameters for my SQL query. I tried something like this, please correct me file=doc1.lst ...
0
votes
2answers
59 views

ssh inside a script with 'command' instead of “command”

I am trying to run commands on various nodes of our cluster automatically via a simples script. I have seen that I can run: #!/bin/bash echo "Machine: "$HOSTNAME; ssh machine2 'echo Machine: ...
0
votes
1answer
16 views

User session connected

When i connect to ssh directly via terminal on unix machine how can i know how many session has been escalated ? i mean Fisrt i connect as root # and su bryan # and su tony # and su emilie # ...
0
votes
1answer
91 views

Linux Bash Script Ideas [closed]

I have been given the task of creating a shell script to show my proficiency in scripting. I am really struggling with ideas on what to do. I would like to create something that is relevant and could ...
3
votes
3answers
246 views

Output to be saved in file named same as the input file [duplicate]

I have one input file and run some command but want the output to be saved with the same name as the input file has. I tried below command but it makes the output file blank: cat file1 | grep ...
1
vote
3answers
202 views

A sort of reversed cat [closed]

I've two documents that are the result of SQL Queries. For exemple i've my Doc1.lst that is : John1 0 Julien 10 Jules3 0 Julie 30 On this Doc1.lst, I used sed to have only ...
1
vote
4answers
43 views

echo \\* - bash backslash escape behavior, is it evaluated backwards?

So in bash, When I do echo \* * This seems right, as * is escaped and taken literally. But I can't understand that, when I do echo \\* \* I thought the first backslash escaped the second one ...
0
votes
2answers
50 views

Regular expression for excluding data within a certain range

I want to remove all the IP addresses which are of the format 10.20.30.* and whose last 3 digits fall in the range 0 to 200 and move all the remaining IPs to a new file. I've put the IP list to be ...
0
votes
4answers
48 views

How to classify these lines in this ASCII file

The ASCII file I have is this: a 1 2 3 1223 b 1 2 3 5 3344 1223 c 1 2 34 a 4 5 c 123 How do I collect the lines below a,b,c respectively? Q: What would I do to get the lines below? a 1 2 3 1223 4 ...
1
vote
1answer
21 views

zwrite handling of “@” symbol

I've been using zwrite to create simple message popups in AIX, and it handles @ symbols weirdly, even when they're strong quoted. I'm running these commands in ksh. As an example, echo '1 @ 2 @@ 3 ...
1
vote
1answer
31 views

Create tar files from shell script with current time stamp

I am trying to create a shell script which will back up my git codebase and save in a specific back up directory with current days name So far I have : #!/bin/bash branch="master" if [ $# -eq 1 ] ...
1
vote
6answers
232 views

Replace \n with blank in a file

I want to replace \n with blank Input file1 A\n D\n Output file2 I want A D I tried below commands but not able to replace please do needful. cat OUT | tr '\n' ' '
1
vote
1answer
61 views

Run shell script from crontab after server stop/start/restart

I want to schedule a shell script in crontab that runs whenever server restarts. It should also run when someone starts the server after it stops abruptly or crashes. How to do so in crontab? Any ...
1
vote
1answer
25 views

How to have getopts functionality when just calling another function within the file

I'd like to have named parameters for my functions. I seem to only be able to use GETOPTS for the main function called from the command line. If I have multiple functions within one file is there ...
1
vote
2answers
21 views

Transform values in a line by first field

I was wondering if there is an easy way to do the following without writing a script. Transform 1234,"a;b;d" 2345,"e;f;g;h" to 1234,a 1234,b 1234,d 2345,e 2345,f 2345,g 2345,h
1
vote
2answers
43 views

Single or Double quotes when defining an alias?

I know that contents of double quotes are expanded, whereas the contents of single quotes are not, such that echo '$1' gives $1 where as echo "$1" gives <the argument - blank in this ...
4
votes
5answers
156 views

How can I use a wildcard to match just files, not directories?

I have a folder called home/homeLife I have a file called home1 home2 and home3 stored in /home I want to move all files that start with home* to home/homeLife/.. I typed mv home* /home/homeLife ...
0
votes
1answer
54 views

How to run privileged bash script as non-root? [duplicate]

I created a simple bash script which contains the command ifconfig. In general I want to execute such a privileged script to run as non-root user. I have tried hown root:users ./path/to/script.sh ...
0
votes
0answers
52 views

'cp:cannot access file' error in script?

This is the code: #!/bin/bash $REPORT_PATH='/data/operational/logs' cp "$(`ls -t | head -1`)" "$REPORT_PATH/new_file" This gives error 'cp:cannot access pda_param'. pda_param file is o/p of ls ...
2
votes
0answers
33 views

Higher-level wrapper for entr or inotifywait

I'm looking for a way to rerun a specific command as soon as any of the files in a subdirectory (perhaps minus selected excludes) changes. Use case I'm working on a project that is self-contained in ...
4
votes
2answers
40 views

stdin 'hop' over process?

Is there a way that stdin can 'hop' over a process? For example, in the following command, cat file | ssh host 'mkdir -p /some/directory && cat > /some/directory/file' This will send the ...
0
votes
1answer
69 views

Shell script printing blank $USER variable when executed by Smartd

I have created a script that smartd daemon (smartmontools) executes as per command below. DEVICESCAN -a -m email -M test -M exec /usr/share/smartmontools/my-script -n stand... Smartd appears to be ...
0
votes
1answer
205 views

Replacing white-space / characters with backslashes [duplicate]

I want to convert a bunch of mkvs to mp4s with the following command: for i in $(ls *mkv); do ffmpeg -i $i -vcodec copy -acodec copy $i.mp4; done; However, the filenames have whitespaces and ...
1
vote
2answers
34 views

Any special permission ssh remote command working on fifo file(aka named pipe)?

I need to redirect some strings to a fifo file with ssh remote command, but always got permission denied, the command I executed is: ssh rundeck@nagios1 sudo su - root -c 'printf ...
0
votes
1answer
16 views

I'm trying to deploy with git to a semi-managed vps, need to write a script to change owners

I'm trying to deploy my sites on my company's semi-managed vps server using this tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps It ...
1
vote
1answer
34 views

Absolute path from user input without losing symlinks inside

Is it possible to convert in a shell script a user input path (absolute or relative) to the absolute path but without losing the symlinks inside, e.g. /a/b/c is the current user dir and c is a symlink ...
0
votes
3answers
44 views

How can I capture the common characters between two strings

I'm looking to compare two strings and capture the common part e.g. FILE0000010985.LOG FILE0000010999.LOG FILE0000011000.LOG If I compare 1 to 2, I want the output to be ...
0
votes
1answer
24 views

Generate SCP string

Generally when I am copying files from a local instance to a server, I find it difficult to generate the SCP string for the server to copy the files. I need to execute the following three commands ...
0
votes
1answer
22 views

find files with two types of extensions last modified over 30 days ago

I want to find all the files in a directory that have not been modified for at least 30 days and end in .xml or .out. This is my attempt to cobble together a couple of references to build the right ...
0
votes
3answers
40 views

Change Multiple (Including No) File Extensions

If I have a directory of files, where some files have an extension like .html and some files have no extension, how do I change them all to, e.g. .txt?
0
votes
1answer
24 views

Which way is safer to read data from /sys

I am attempting to write a program that will monitor the temperature of various hardware components. The language I chose for it is Java. Now there are two ways I could read the temperatures: a) Do ...
0
votes
5answers
163 views

How to get current working directory? [duplicate]

I want to have a script that takes the current working directory to a variable. The section that needs the directory is like this dir = pwd. It just prints pwd how do I get the current working ...
2
votes
4answers
54 views

Completely buffer command output before piping to another command?

Is there a way to only execute a command after another is done without a temp file? I have one longer running command and another command that formats the output and sends it to a HTTP server using ...
2
votes
2answers
32 views

Why is a variable passed to the su command, but not an array from the same scope?

In the example below, why does $var get passed to the su in the start function, but not the array modules ? #!/bin/bash var=cat modules=( one two three four ) start() { su gleventh -c "for i in ...
0
votes
2answers
54 views

Why would the prompt get overwritten?

p_ash-3.2$ cp some_file1234.html /some/loc/ation/ofthe/some_file1234.html.html_Backu Have been seeing this intermittent issue with the command-line, while typing longer lines as part of any command, ...
1
vote
1answer
57 views

remove lines where a field's value is less than or equal to 3 - sed or awk?

I need to remove every line that has a value of 2 or less in the 8th field (column). My data looks like this: 12-31 Airport 189 379 41 49.70946503 -124.91377258 2 2880 30.8 01-01 ...
0
votes
0answers
23 views

convert from one memory format to another and find the difference between them

Using shell scripting, how can I convert from one memory format to another and find the difference between them? I want to compare current rate and previous memory rate (Where we need to compare ...
0
votes
2answers
22 views

How to search parenthesis by ack

I want to search for a parentheis ( using ack, but neither using ( nor \( worked. The first one ("(") is recognized as a multiple line command. The second one ("\(") is treated as an invalid regular ...
1
vote
1answer
55 views

how to locate a name-not-specified file in bash? [closed]

I have a bash like this to easily upload a file to my server: FILE=../"$1"/1.txt scp 1.txt remoteserver #upload the file to a remote server. The $1 is for input directory and I have a lot of ...
17
votes
2answers
900 views

Renaming the current directory from a shell - possible?

Is it possible to rename the current working directory from within a shell (Bash in my particular case)? If I attempt to do this the straightforward way, I end up with an error: ...
1
vote
1answer
32 views

Specify the type of field to modify in a file

I have a list of clients, "code", "name", "location", "etc" and I want to make a function that asks the employee to give the client's code and then the field he/she wants to change. For example, ...
2
votes
3answers
67 views

Calculate date difference between Last modified date of a file and NOW using shell script

I am trying to calculate the time elapsed since the log file was last updated. I guess following commands will be used lastUpdate=$(date -r myLogFile.log) now=$(date) How can I subtract them and ...
3
votes
5answers
173 views

Pick the latest file based upon the sequence number given in the file name

I have a requirement, I have few files in a directory, I need to pick the oldest one for processing. For Exp: I have below files in /tmp directory: Sample_0000237826-001_xyz.dat ...
0
votes
0answers
12 views

sending NEDIT to background on launching

I have this problem - for opening nedit it will open in the foreground. Then either you open it using & ex- prompt> nedit & is there any way where I can open nedit directly in the ...
2
votes
4answers
57 views

space check on unix machines

I am having space issues on 1 of the UNIX servers. I am executing the below command to check the space utilization. But this command is very slow and takes hours of time to give the result. du -sg * ...