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

i'll need a Shell script that scans thru creation dates of all patches (ideally only the security ones but
if this is not possible, then all patches) installed in an RHEL 7 server, get the latest one, compute
the difference from today's date & give the difference in number of days & if the difference is
more than 90 days, echo out a message, "It has been more than 90 days since last patch)

Purpose is to check the last patch date & remind Linux admins.  Believe RHEL releases patches
at least every 3 monthly?
On Demand Webinar: Networking for the Cloud Era
On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Hi all i am managing email server ,i have user data in mysql. group list in sympa and user detail in active directory. if i want to romove any user from multiple group i do it manually one by one from all group,i want to make it automated through shell script,please suggest me best possible script to remove a user from multipe group and  from sympa,mysql, and ldap at same time.
Hey there,

I have an Exchange 2016 Hybrid setup with O365. All active users will be in the cloud, however terminated users will be migrated back to on prem and either left in the database for a term or exported to a PST. What I'm trying to do is to get my powershell script to pause until the batch completes and then continue on with some other tasks. I am aware of the Out-Null option but I don't think that's going to work in this case, as I need to confirm progress/completion after querying the status. I thought about using an Outlook rule that kicks off the remainder of my script after the migration notification is sent out but that relies on an outlook profile. Is it possible to do what I'm looking for or do I need something else in play here?

Basically I need to run the script with paths related to the shell script file location, how can I change the current directory to the same directory as where the script file resides?
Every month  we wud like to sftp over  Win 7 n Win 10 patches (.msi  .msu, ??)  to about 20 remote PCs that are located in our supplier/service providers premises as these PCs are npt part of our corporate's AD/domain n we cant Rdp/remote to them for security reason.

Can anyone provide a batch or cmd scripts tt will scan for the presence of msi or msu (or any extensions tt MS patches may come in) in a folder (say c:\MSpat )  n will execute them in silent mode (ie dont need us to input/intervene) but dont reboot after patching.  Ideally, output logs ( >>) or error ( 2>>) to 2 separate logs.  Housekeep away the patch files
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

I have three scripts that I run in PowerShell to get some information I need from remote workstations.   I would like this to be accomplished with just one script instead of three.   What I need to get from the remote stations is:

IP Address
MAC Address
Operating System
Determine if the workstation is a 32-bit or 64-bit
Serial Number or Service Tag Number

I need to be able run these scripts using a list of either Hostnames or IP Addresses in a text file or csv file.  The reults also have to be exported to a CSV file.

Here are the scripts I use.   Not pretty, but they work.

Get-Content C:\Users\username\Desktop\IPs.txt |
  Where-Object { Test-Connection $_ -Count 2 -Quiet } |
  ForEach-Object {
    $IPAddress = $_
    Get-WmiObject Win32_NetworkAdapterConfiguration -Filter 'IPEnabled=TRUE' -Computer $IPAddress |
    Where-Object { $_.IPAddress -contains $IPAddress } |
    Select-Object @{n='IPAddress';e={ $IPAddress }}, MACAddress, DNSHostName
  } | Export-Csv C:\Users\username\Desktop\MACAddressReport.csv -NoTypeInformation

Open in new window

$computerlist = Get-Content C:\Users\username\Desktop\IPs.txt
foreach ($computer in $computerlist) {
    if((Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
        Get-WMIObject Win32_OperatingSystem -ComputerName $computer |
        select-object CSName, Caption | export-csv -Path C:\Users\username\Desktop\MACAddressReport-2.csv -NoTypeInformation -Append

Open in new window

get-content C:\Users\username\Desktop\HostNames.txt |
   select-object `
     @{n = 'IP'; e = { [Net.Dns]::GetHostEntry($_).AddressList } },
     @{n= 'Name'; e = { $_ } } |
   Export-Csv C:\Users\username\Desktop\IPAddressReport.csv -NoTypeInformation

Open in new window

Any help would be much appreciated.

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.
Free Tool: SSL Checker
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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  ))
Hi Experts
I need a batch file to change folder permissions and sub folders to the following
remove every users permissions except the administrator and the administrator only have the read only option
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?

If any one can help please, I need a power shell command  list name, email address and mailbox size in MB from a particular domain.  My environment is Exchange 2010 with 250 accepted domains. Thanks for your help in advance.
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.
What is the easiest way to track and manage CIDR blocks/subnets?

I need to automate this processes when configuring/building a new environment to use a new CIDR block/subnets not already in use by other environments and add this information to a tracker?

So I want to have some sort of file that keeps track of all the CIDR blocks/subnets that are currently in use checks and gives me the next CIDR blocks available. How would I implement this logic?

  Client 1
client 2
client 3

    #Should give me this next available block

Open in new window


I am a newbie in shell scripting!

I need to create a shell script that connects to the oracle 11g database and list all the tables that ends with _tmp (both lower case or upper case) and deletes them if it's equal or greater than 30 days.  I should be able to pass the variable parameters for database name, instance name and the number of days.  Also, it should skip SYS and SYSTEM schema tables but checks for all other schema tables in the database.

Please help me ASAP.

Appreciate it very much and thanks in advance.
Hi I want to create a script in SOLARIS server which rotates the logs of the instances being used. And also delete them after specific duration.Since , application logs being created in real time cannot be copied to other file tozip or delete them  as the writing of logs in actual file will be stopped.Pls tell me how to achieve this with a script.
Enroll in August's Course of the Month
Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Hi - I have downloaded the tcl curl solution to my windows 7 machine.  The directory is located in c:\tcl\lib\tcl8.6\tclcurl.  I am trying to run the https test case. When I run the https.tcl script, I am receiving the following error:

Could not init a curl session: invalid command name "::curl::init"

I have the curl exec downloaded and installed in my PATH environment directory.

Any thoughts?

Thanks for the assistance.
I need to Schedule she'll script to run in batch mode on unix using a detach screen.  I want the script to run in a screen I can reattach to later..  I need command to start script in screen.  I will schedule this script to run daily.
Hello experts,
I have a perl script that does the following::
-get log files from a directory;
-zip them
-send them over smtp to a given mailbox
-redownload them from the mailbox
-crypt them using pgp
-crypted files gets pushed on ftp
-delete the original file

What i would like to do is:
-Delete the ftp sending part, instead move the files in a local given directory

Attached you will find the script.

Thank you in advance!!!!
Hi Dears,
I want write a CLI for my centos, when a linux boot, it only accept my commands that i defined before,
is a sample for it?
I had this question after viewing send ksh history to syslogd on AIX.

I'm trying to extend the above solution to bash on AIX, and bash and ksh on Solaris, with very little success. While I post my results, I wanted to know if someone has already done this before.

Thanks much in advance!
I had this question after viewing send ksh history to syslogd on AIX.

I used the solution above. Thanks to @woolmilkporc!

However, whenever the command includes a grep, it appears to spin off a job. Here's an example.

$ ls -l z*
z* not found
$ ls -l | grep z
[1] +  Done                    ls -l | grep z

I can't figure out why the job gets spun off when the command includes a grep.

Please can someone help?

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.