Shell Scripting





The term 'shell' refers to a general class of text-based command interpreters most often associated with the UNIX and Linux operating systems. Popular shells include Bourne, Debian Almquist (dash), Korn (ksh), Bourne Again (bash) and the C shell family (csh). Some view the DOS 'cmd' prompt as a minimal shell of sorts. It is also possible to install Cygwin on Windows and emulate a full Unix environment with complete shell capabilities. Terminal emulators, such as xterm, GNOME Terminal and OS X Terminal, can be used to access shell.

Share tech news, updates, or what's on your mind.

Sign up to Post


This is a Shell Script to summerize the output of errpt command in Unix AIX but something wrong : :

errpt | awk '{print $1}' | sort | uniq -c | \
        grep -v IDENT > err_.junk
printf "Error \t# \tDescription: Cause (Solution)\n\n"
foreach f (`cat err_.junk | awk '{print $2}'`)
set count = `grep $f err_.junk | awk '{print $1}'`
set desc = `grep $f errs.txt | awk -F '{print $2}'`
set cause = `grep $f errs.txt | awk -F '{print $3}'`
set solve = `grep $f errs.txt | awk -F '{print $4}'`
printf "%s\t%s\t%s: %s (%s)\n" $f $count \
                               "$desc" "$cause" "$solve"
rm -f err_.junk

Here is the output error :

./[5]: 0403-057 Syntax error at line 5 : `(' is not expected.

Thanks for any help
Rowby Goren Makes an Impact on Screen and Online
LVL 12
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

I have a bash shell script that I want to call a Oracle DB stored procedure with (procedure is in a package with public interface), I am running it on Cygwin:


if [[ $1 = '' ]]; then

  echo "usage : <master conect string> "
  exit 0

test_db1=`$ORACLE_HOME/bin/sqlplus -s $1 << EOF
set heading off
set pages 0
set feedback off
select 999 from dual;


test_db=`echo $test_db1`
echo test_db: ${test_db::-1}
echo ${test_db}

if [[ ${test_db::-1} != 999 ]]; then

  echo "Can NOT connect to database with the given connect string"
  exit 0



`$ORACLE_HOME/bin/sqlplus -s $CONNECT_STRING << EOF > /c/temp2/log.txt

set heading off
set pages 0
set feedback off

      --GRANT EXECUTE ON COPY_STUDIES.ins_trial2 TO tsm10;
      execute PackageName.procedure_name(name=>'trialname',client_div_source=>'source1',client_div_target=>'target1',ftuser=>'user1');

If I run the procedure by itself in a sql script, it works.  In the bash script, nothing happens and no error gets returned.  Can someone tell me what I am missing?  Thanks.
Hello All,

I would like to get the list of all the public folders and the size. I got the below cmdlet, however i was unable to get the size of PF.

I just want identity, User, AccessRights and Size.

Get-PublicFolder -Recurse | Get-PublicFolderClientPermission | Select Identity,User,{$_.AccessRights} | Export-CSV "C:\PFPermissions.csv"

Can anyone please help me.

This is using SuSE 11 with SP4. Recently, I came across an online article discussed about how to use pmap to display the actual mapping, memory in active/cached and so on.
Please see the full command below,

 for i in `ps -eaf | grep “any application process” | grep -v grep | awk '{print $2}'`; do echo -n "PID $i actual memory usage is :" >> totaluse.txt; pmap -d $i | grep -i "writeable/private: " >> totaluse.txt; done

I was ended up with "nothing" when copy and paste the whole command to the terminal. Can I create a bash script? if so, please enlighten how, thanks.

i started new for python, i would like know the equivalent python code for below shell script.

while read n
        curl -u admin:admin@123 -X GET$n$data | /usr/bin/jq '.id' >> isad.csv

done < filename

where filename contains

This is a php script, which basically does the send mail function via terminal shell, I am studying it and the curious thing is that it worked in my tests only in the Ubuntu 14.04 versions with php5 and postfix. But I could not get it to work on Ubuntu 18.04 or Debian 9. I would like to ask for help to change the code in order to make it work in those versions. Thank you.


Need a unix script to loop through thousands of folders and write a file listing the folders that contain less than x amount of subfolders.

Thank you.
Need a python script to copy yesterday files to a destination location and gzip them in destination directory
need an archival script that runs on a nighty basis

we maintain our logs for a given month in a directory


on a nightly basis we have to copy logs to corresponding months folder with date and tar and gzip

if the directory does not exist for the month we have to create it when copy and tar the files,

ex : /a/b/c/archieve/`date +`'%Y-%m'`/`

we should be maintaining the archived files for the last 3 days and hould be removed older than 3 days
Office 365 user mailbox and online archive full issue: I am the new IT manager for a company and have inherited a problem. The company has never had policies for mailbox size enforcement or archiving. I have a user with a full mailbox (49.5GB), a 180GB In Place/online archive, and ten local pst files from previous reduction attempts.

I'd like to move all older mail in to a different online archive, and free up the current mailbox and OA to function properly, be modest in size, and also establish better mail management techniques (I'll train the user in the last bit).

Plan A: I'm looking for Azure Exchange powershell commands that will move mail from the active online archive to a  new, secondary user online archive I created for him. My hope is to move all mail older than a year over to the secondary archive, which will be smaller in size than the current one, and then import the local psts in to it so that all the old emails are in one location.

Plan B: Perform the requisite tasks to switch them to the new primary and online mailboxes, leaving the original as the long term holding archive (less desirable, as I won't be able to bring all the old psts in to the almost full one).

I'm looking for powershell commands to copy from one OA to another, and optionally remove a certain date period from both main and OA.

Please ask if I haven't been clear enough about the situation or what I'm asking for. Thanks in advance!
Starting with Angular 5
LVL 12
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Hi Experts,

I am looking for custom weblogic admin server startup script which can redirect output "directory_path/AdminServer.out" file. and rotate each time we execute the startup script so that older .out file moves to backup file.

example :


Any help will be really appreciated.

Thank you
i need to truncate and load data into informix table .. is there a way by which i can used dbload to do it i am using a shell script to load the data .. but it always appends into the table...also i am trying to do a upshift of character data while loading itself .. but that throws error ... as syntax mismatch while using the utility.. my control file is as below

"control.file" 3 lines, 83 characters
FILE "file.unl" DELIMITER '|' 3;
INSERT INTO TAB1(name,age,salary)
VALUES (UPPER(f01),f02,f03);
Redirecting output ([n]>[|]word), when does "n" greater than 2 make sense?

This question is about redirecting output in bash, see:

The general format for redirecting output is:


I already understand the basics (you're just redirecting a file descriptor to a file for writing). But, can someone give me an example when it does make sense to use for example: 3>. In other words, if n is greater than stdin, stdout, stderr (>2), for what would you need it?

I can do:

echo 'test' 3> test-file.txt

Open in new window

This will not write anything to "test-file.txt". This is logical, because now there is just a file descriptor with number 3 pointing to test-file.txt for writing, but there is no input to fd=3 so there is also nothing to write.

The only way to give it some input is to connect file descriptor 3 for reading with a file (or connect it to the output of a pipe). But if you would do that, then fd 3 doesn't point to test-file.txt anymore. So then in the end, fd 3 was connected to test-file.txt without any reason.

So in what kind of situation it's useful to use >n with n greater than 2?
By default, the first three rows of a "file descriptor table" consists of:

FD 0 (standard input,  associated with keyboard)
FD 1 (standard output, associated with screen)
FD 2 (standard error,  associated with screen)

Open in new window

These file descriptors point to one or more rows in the "open file table". Imagine we only have these three file descriptors. Then how does the "open file table" look like?

Usually all three file descriptors point to the same file, but that doesn't mean they point to the same entry in the "open file table". So how the open file table looks like?

_ | offset | reference count | permissions | flags | pointers
_ |    ?   |        ?        |      ?      |   ?
possible more rows

Open in new window

The lsof command shows for example:

lsof        721    root    0u      CHR              136,1       0t0          4 /dev/pts/1
lsof        721    root    1u      CHR              136,1       0t0          4 /dev/pts/1
lsof        721    root    2u      CHR              136,1       0t0          4 /dev/pts/1

Open in new window

The file "/dev/pts/1" is CHR (character special file). They all point to the same file.
I'm also wondering why it's for example "0u" and not "0r"? The file descriptor 0 stands for input, so it only has to read something.

r for read access;
w for write access;
u for read and write access;

Open in new window

I would expect something like: 0r, 1w, 2w instead of 0u, 1u, 2u? And what are the offsets et cetera?
[root@myserver~]# /bin/ksh
# echo $SHELL

I wonder why ksh is not showing up when i did ksh or /bin/ksh?

I am used with bash, specific app uses ksh so i had to switch.
Batch file to ping all network hosts to determinate witch are powered up and store output to a text file

Hello, I need to write a Batch file to ping all network hosts (readed from a hostslist.txt) and write UP/DOWN state to a text file.
how to configure aws configure in docker file

my docker file

FROM ubuntu

RUN apt-get update && apt-get install -y awscli

cmd docker pull mariadb
cmd  docker pull mysql
CMD ["/"]
 aws configure set aws_access_key_id default_access_key xxxxxx
 aws configure set aws_secret_access_key default_secret_key xxxxxx
aws configure set default.region us-west-2
aws s3 cp s3://mariadbs3bucket/test.txt /test

 mysql -u xxx-pxxx --host xxx -P 3306  --socket=TCP/IP  -e "USE myDB; insert into values(50000);"

the above both command are working fine while running in ec command line
there i have set the aws configure
data no align after i do cat in unix this is my script
cat data*.txt|grep -v ^UNIT_CDE|awk '{print $1,",",$2,",",$3,","$4,",",$5,",",$6,",",$7,",",$8,",",$9,","$10,",",$11,",",$12,",",$13,",",$14,",",$15,","$16,",",$17,",",$18,",",$19,",",$20}' >>  mergetstneg.txt
I need to write a shell script to login to 5 linux servers using ssh and run a command remotely.

ssh keys are already.  key less authentication is setup already.
CompTIA Security+
LVL 12
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.


Is symbolic link, bash convention.
See -l.

Is symbolic link.
Treats the TestString as a pathname and tests whether or not it exists, and is a symbolic link. May also use the bash convention of -L or -h if there's a possibility of confusion such as when using the -lt or -le tests.

Is symbolic link, bash convention.
See -l

What are the differences between these three?

"-h" has "bash concention" and "-l" not. But what is the difference in practise? Can someone give me an example of the difference?

And why it's "-L" and not "-H"? "-L" is about the bash convention, but "-l" not. However, "-h" is. So then I would expect "-H" instead of "-L".

I don't need it for something right now, but I'm trying to understand the Apache documentation.

I need to run this command in a multiple linux server :

id -u user2 &>/dev/null || useradd -c "SSH account" -d /home/tools user2; echo 'password2' | passwd user2 --stdin

The idea is to create a text file with some IPs one per line and running the above command for each IP

But in somes linux servers, I can directly login as root@ip without password, but others linux servers I need to log as specific user@ip with password and switch to root

Any idea to do that ?
I want to write a init script to stop and start the MongoDB.
when i start the application using a specific command, its does spawn a process however a i am not getting the prompt back.  I have been told you to press CTRL+C to get the prompt.

This is usual behavior for starting the application.

How do i get the prompt back using the shell script?

[root@myserver]# bash -x /etc/init.d/app start
output omitted

Session terminated, killing shell... ...killed.

when i run #ps -ef | grep app, i noticed the process is running. when i talk to the app support, they said its normal behavior.  Not sure why this happens.
I am working on script where i have to create a init script to start/stop the application. However the application does not stop properly. i had to kill 3 - 4 process by grepping the PID ids.

How can i do this?
I want to know how can I start a script at the system startup. I tried to make a sh file under /etc/rc.d/rc3.d/ but I rebooted the Os and it does not start my script as I want. :(.


Shell Scripting





The term 'shell' refers to a general class of text-based command interpreters most often associated with the UNIX and Linux operating systems. Popular shells include Bourne, Debian Almquist (dash), Korn (ksh), Bourne Again (bash) and the C shell family (csh). Some view the DOS 'cmd' prompt as a minimal shell of sorts. It is also possible to install Cygwin on Windows and emulate a full Unix environment with complete shell capabilities. Terminal emulators, such as xterm, GNOME Terminal and OS X Terminal, can be used to access shell.