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

How can we Transfer one folder to another folder on windows server of big size about 300 GB. I have to do automation via Jenkins.
Upgrade your Question Security!
LVL 11
Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Where can I obtain a good tutorial on power shell scripting. Also where can I obtain canned scripts
Eventhough there are no big files there still /opt/ is showing 100% full it very confusing to me. Can anyone help me on this please

root@[opt] # lsof | grep -i deleted
root@[opt] #

Open in new window

root@[opt] # lvs
  LV          VG                  Attr       LSize   Pool Origin  Data%  Meta%  Move Log Cpy%Sync Convert
  isvol1      HKLVAUEDM08_applvg1 -wi-ao----  10.00g
  isvol2      HKLVAUEDM08_applvg1 -wi-ao----  10.00g
  isvol3      HKLVAUEDM08_applvg1 -wi-ao----  10.00g
  tsavol      HKLVAUEDM08_applvg1 -wi-ao----  10.00g
  wmstorage   HKLVAUEDM08_applvg1 -wi-ao----  10.00g
  homevol     rootvg              -wi-ao----   3.91g
  oprvol      rootvg              -wi-ao---- 320.00m
  optvol      rootvg              owi-aos---   3.91g
  optvolsnap  rootvg              swi-a-s---   3.94g      optvol  95.39
  rootvol     rootvg              owi-aos---   5.88g
  rootvolsnap rootvg              swi-a-s---   2.91g      rootvol 69.49
  scbmonlv    rootvg              -wi-ao----   1.00g
  semavol     rootvg              -wi-ao----   1.00g
  swapvol     rootvg              -wi-ao----   5.88g
  tmpvol      rootvg              -wi-ao----   3.91g
  usrctmvol   rootvg              -wi-ao----   2.94g
  usrgemsvvol rootvg              -wi-ao----   1.00g
  usropenvvol rootvg              -wi-ao----   1.97g
  varvol      rootvg              owi-aos---   3.91g
  varvolsnap  rootvg              swi-a-s---   3.94g      varvol  88.16

root@[opt] # df -PH | grep -i "/opt" | grep -i root

Open in new window

How Can I Copy Data From One Spreadsheet and append to another existing Spreadsheet?

ID Name
1   ABC
2   XYZ

MasterWorkSheet (Contains previous information + SourceWorkSheet info )
ID Name
11   DEF
22   USD
1   ABC
2   XYZ

Help would be appreciated.
I have created two jil files name AY.jil and PY.jil. I have three issues which are as follows:

1. how do you add a global variable value from a shell script program to a jil

2. PY.jil  needs to check every five minutes on the completion of the AY.jil
    jobs and AY.jil needs to check every five minutes on the completion of the
    PJ.jil jobs.

3.  How do you setup the watch_file in each jil to check every five minutes?
4.  How do you set up the success command for the file dependency?

I am getting this error :

I am only interested in reading in the global variable value 2 in PJ.jil:
  sendevent -E SET_GLOBAL -G "DIFF_VALUE=2"

Here is part of my shell script program:

while read DIFF_VALUE FLAG
	if [ "${DIFF_VALUE}" -ge "2" -a "${FLAG}" = "Y" ]
		sendevent -E SET_GLOBAL -G "DIFF_VALUE=2"
	elif [ "${DIFF_VALUE}" -lt "1" -a "${FLAG}" = "N" ]
	        sendevent -E SET_GLOBAL -G "DIFF_VALUE="
done < ${DIFF_FILE}

Open in new window

Here are my jil progams (AY.jil and PY.jil):

Insert PJ_job: cmd_job
job_type: CMD
command: /path/to/script/  DIFF_VALUE=$${DIFF_VALUE=2}
watch_file: /path/to/script/AY.jil
watch_interval: time_in_mins
machine: machine_name
owner: user_name
condition: s(/path/to/AY.jil)

Insert AY_job: cmd_job
job_type: CMD
watch_file: /path/to/script/PJ.jil
watch_interval: time_in_mins
machine: machine_name
owner: user_name
condition: s(/path/to/PJ.jil)

Open in new window

Please see the attached XML, there are multiple resources,

I want to be able to find the resource whose name is "jdbc/PegaRULES" and create a new xml file which has only that resource.

For example: newfile.xml should be like:

<?xml version='1.0' encoding='utf-8'?>
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  See the License for the specific language governing permissions and
  limitations under the License.
<!-- The contents of this file will be loaded for each web application -->

    <!-- Default set of monitored resources -->

Open in new window

Thanks to Rick_2CA -

I have been able to Modify this script to include: TotalDeleteditemSize and TotalDeleteditemCount

This outputs the below and works exactly how I want:


The part I am having trouble with, and where I would like a push in the right direction is how to obtain the ArchiveTotalDeleteditemSize & ArchiveTotalDeleteditemCount (The count and size of data that CAN be archived, same as what is output from "ArchiveItemsSizeBytes")

Below is the script, that I have manipulated to include the

TotalDeleteditemSize & TotalDeleteditemCount......

I have attempted to match what was already in the script, by copying the code, and changing the values (Via Powershell ISE), However, I just end up with nothing being returned or getting the identical results as the ArchiveItemsizebytes

Essentially I am after the Archivable size & Count for recoverable deleted items

Any assistance would be greatly appreciated!!!

If I have worded anything wrongly, or something does not make sense, please let me know, and I will be happy to clarify...

# Exchange 2010 Mailbox PreArchive Statistics
# Purpose:  Query mailboxes for mail older than X days in order …

today=`/bin/date -d yesterday +%Y%m%d`
#sleep 600

ftp -n -i abcd_servername <<!
user username Pswd@123
cd /home/abcd/
lcd /appl/aaa/logs/stats
mput total_$server.$today
mput number_$server.$today
I have already written a GUI in Tk to consolidate all scripts at one place.
The logs are similar with some changing text.

Can you please help me in transforming my shell script to tcl and integrating it with the GUI .

I have attached the log file , shell script and the GUI code (unfinished)


i have a csv file populated with email addresses
i also need there SamAccountName
Rather than look each of these up
Is there a method that could query the email addresses in the csv and populate another column with the SamAccountName?
Vote for the Most Valuable Expert
Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

I have a mailbox with tons of folders ( over 50000 folders ) and the person put lot of special characters that we think it is causing the activesync problem keep reloading.

so I would like to know, is there a powershell script where I can identify the folder that have special characters and rename it ?
i have a code like this


echo "leaving the function "
exit $1 ## should call builtin function

if [ ${AUTORUN} = "Y" ]
echo "cannot AUTORUN"
exit 1      #should call user defined function
echo "can AUTORUN"

is it possible to do it ?
I need help creating a Script that will Check if the Uptime(Hours) is exided on Windows 10 Operating Systems. I am not that Scripting guy just a newbie in the Scripting world.The following will be the Parameters I would like to have:

Parameter 1 specifies after how many hours without rebooting the user is asked via a message box  to restart their computer themself or to shut down .

Parameter 2 specifies after how many hours without restarting will the script plan an automatic restart in 60min (with no prompt for cancelling)

The script must be controllable with at least two parameters
Thank You in Advance
Hello Team,

Require a shell/perl script with below steps.
1) When disk space reaches 75%, trigger a cron job and move the old .arc files to another location.
2) Clean up the files in a folder by keeping only 8 hours of data available and it should be run every 15 mins.

Hello All,

I wanted to run the below script

Get-WinEvent @{logname='application';starttime=[datetime]::today } -ComputerName "ABCDEFRR56d" | select timecreated,task, TaskDisplayName

Put the output to a excel file and send email to a distribution list.

Can any one help me with a script?
I had this question after viewing Script for testing ping and telnet.

How can i modify this script to test telnet and mutual auth only

Expected Output
Flow ID |       From               |             To                      |          Test           |         STATUS
1            |  |       |       Telnet            |             OK
1            |  |       |       Mutual Auth |             OK
I am trying to create a script that I can use to log into remote pc's, on a domain, with admin privileges and uninstall software and then display a pop-up.

so far I have this: wmic /failfast:on /node:"D:\computers.txt" product where name="Java 8 Update 144" call uninstall /nointeractive

in some cases I also need to delete the registry keys.

 REG DELETE "HKEY_CLASSES_ROOT\Installer\Products\4EA42A62D9304AC4784BF2238110440F" /f

REG DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products\4EA42A62D9304AC4784BF2238110440F" /f

REG DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\4EA42A62D9304AC4784BF2238110440F" /f

REG DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F32180144F0}" /f

can you please help?
Hi I have a  data like below format

Site	Variable	Units	Model	29/00Z	29/06Z	29/12Z
CQT	500mbHeight	dm	MASS	588.4	589 	588.9
CQT	500mbHeight	dm	NAM	589.4	589.5	588.2

Open in new window

How can i transpose as one below (like repeat first 4 columns for transpose of each row after 4th column
CQT	500mbHeight	dm	MASS	29/00Z	588.4
CQT	500mbHeight	dm	MASS	29/06Z	589
CQT	500mbHeight	dm	MASS	29/12Z	588.9
CQT	500mbHeight	dm	NAM	29/00Z	589.4
CQT	500mbHeight	dm	NAM	29/06Z	589.5
CQT	500mbHeight	dm	NAM	29/12Z	588.2
CQT	500mbHeight	dm	NAM	29/18Z	589.6

Open in new window

Hi Im trying to display the output of the shell script in php.

When user login to the page it have to get the username and it should be passed to the shell script and that shell script output should be print on the webpage.In php the shell script is not getting executed

Please help me to make this.

$result = shell_exec('./ >> temp.log');
echo "<pre>$result</pre>";
echo "<div id='User' style='float:right;color:#0000FF;' 'font-weight:bold;'>Welcome , " . $_SESSION[$result]. " </div>";

Open in new window

Shell script:-
grep -A 1 "$username"  /mnt/eseesn60/ee_groups_see/ee_magicdraw/bittu/user.txt > /mnt/eseesn60/ee_groups_see/ee_magicdraw/bittu/get.txt
egrep -Ri ',' /mnt/eseesn60/ee_groups_see/ee_magicdraw/bittu/get.txt > /mnt/eseesn60/ee_groups_see/ee_magicdraw/bittu/getname.txt

Open in new window

Free Tool: ZipGrep
LVL 11
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.


Please help me out for below problem...i want create the one shell script to upload file through lsftp and using below command but it is now working.

 lftp -oIdentityFile=/.ssh sftp://test:test@XX.XX.XX.XX -e "put tmp.txt.gpg; bye"
I am compressing files into one zip file and I am using the WSFTP script Editor/debugger and I want to rename the dest file to I am using the RENAME command as FirstFileName.txt abc-[YYYY][MM][DD].zip and that is what I get in the dest folder. I need the current date to be inserted.
Can someone help me out?  I need a shell script that can make an sftp connection with a password - installing the keys is not an option.  The scripts that I have (pasted below) throw an error saying that the command "expect" is not available.  Any help would be GREATLY appreciated.


expect << 'EOS'
spawn sftp USERNAME@ip_address:/path/to/folder
expect "Password:"
send "PASSWORD\n"
expect "sftp>"
send "put file1\n"
expect "sftp>"
send "bye\n"
Hello Folks,

I have a script that came along with a project that someone was working on and requested that I continue to use because the initial person who set it up had it running in the environment. Anyways the purpose of the script to check to see if the "ttt.service" was been stopped and restart the service if this is true.
Now I've added the script, given below to a .bat file and created a Scheduled task to run the file every 5 minutes to check and restart the service it never runs. I then opened a command prompt and attempted to run the script from the prompt and yet it still didn't work.

Not really sure what im doing wrong and need some assistance..

@echo on
for /F "tokens=3 delims=: " %%H in ('sc query ttt.Service ^| findstr "STATE"') do (  if /I "%%H" NEQ "RUNNING" (      net start ttt.Service  ))
I currently login to the time from website using the following script.

browser = webdriver.Chrome('E:/Shared Folders/Users/runnerjp/chromedriver/chromedriver.exe')
username = browser.find_element_by_id("EmailAddress")
password = browser.find_element_by_id("Password")
login_attempt = browser.find_element_by_xpath("//input[@type='submit']")

Open in new window

it works but I find using Chrome web driver is hammering my CPU. Is there an alternative code I could use that does not mean I need to physically load the page to sign in?
I'm running a script on Unity to run multiple applications at the same time with different settings the problem is every time I try to run the .sh file it gives me an error : Player data archive not found at 'location', using local filesystem. I looked up on google but no one seems to have the answer to this problem, do you have any idea why this is hapenning?

Thank you!

Log file attached.

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.