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

hi experts
could you help with below please

Sample string for this question
Could not find '/dir1/dir2//dir3/null_component_deploy.properties'
Could not find '/dir1/dir2//dir3/valid_file.properties'

1. how to ignore line 1
2. but catch line 2



Existing sample string/regex rule that experts exchange helped me which is working fine only for reference
/tmp/path - No such file or directory.
/tmp/shm - No such file or directory.
/dir1/validate_path - No such file or directory.

Working regex to exclude first two lines but catch the third line
/^(?!.*(tmp|log|shm))(.*No such file or directory.*)$/
0
Free Tool: Site Down Detector
LVL 9
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Hi Experts,
could you advise what is the best way to sort directories which has string with number prefix in bash please?

Scenario/Actual
DIR_NAME_Drop0
DIR_NAME_Drop1
DIR_NAME_Drop10
DIR_NAME_Drop2
DIR_NAME_Drop3
DIR_NAME_Drop4
DIR_NAME_Drop5
DIR_NAME_Drop6
DIR_NAME_Drop7
DIR_NAME_Drop8
DIR_NAME_Drop9


Expected
DIR_NAME_Drop0
DIR_NAME_Drop1
DIR_NAME_Drop2
DIR_NAME_Drop3
DIR_NAME_Drop4
DIR_NAME_Drop5
DIR_NAME_Drop6
DIR_NAME_Drop7
DIR_NAME_Drop8
DIR_NAME_Drop9
DIR_NAME_Drop10

Script for your reference
mkdir DIR_NAME_Drop2
mkdir DIR_NAME_Drop3
mkdir DIR_NAME_Drop10
mkdir DIR_NAME_Drop0
mkdir DIR_NAME_Drop1
mkdir DIR_NAME_Drop4
mkdir DIR_NAME_Drop5
mkdir DIR_NAME_Drop6
mkdir DIR_NAME_Drop7
mkdir DIR_NAME_Drop8
mkdir DIR_NAME_Drop9

Open in new window

0
I have been using this power shell command to create a text files that lists the currently installed programs on Windows 10 computers:

Get-WmiObject -Class Win32_Product | Select-Object -Property Name > C:\PCapps.txt

Open in new window


The problem is that this command lists only the names of the installed programs.

I would like to run a command that will display the complete list of everything that is displayed within the Programs and Features applet: Software name, publisher, installed on, size, & version.

What is the correct syntax of a command that will display all this information?
0
I need to replace one of the tag attribute value from one file to other xml file. we need to update "0 58 40 * * ?" from ServiceContext.xml_pre_455 to ServiceContext.xml. we don't have xmlstarlet.

ServiceContext.xml_pre_455

<bean id="service_TriggerOfflineDBProducer" class = "org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail">
            <ref local="service_OfflineDBProducerJob" />
        </property>
        <!-- Schedule OfflineDB producer at 3:30 everyday, preferably after DIMP runs. -->
        <property name="cronExpression" value="0 58 40 * * ?" />
    </bean>


ServiceContext.xml

<bean id="service_TriggerOfflineDBProducer" class = "org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail">
            <ref local="service_OfflineDBProducerJob" />
        </property>
        <!-- Schedule OfflineDB producer at 3:30 everyday, preferably after DIMP runs. -->
        <property name="cronExpression" value="0 26 15 * * ?" />
    </bean>
0
I need to convert all files in a folder from binary named zone format to text zone format.

the command is

 named-compilezone -f raw -F text -o myzone.ch.hosts.text myzone.ch myzone.ch.hosts.binary

the present binary files are always named like "myzone.ch.hosts" - after conversion they should have the same name.

but how do i do that automatically for all files in the folder?

Thanks!
0
Hi, I have requirement for FTP, it's any script or command can accomplish this?

1. FTP ServerA receive files from FTP client

2. FTP ServerA able detect receive the file from FTP client is successful then perform FTP the same file to another FTP ServerB.

3. All the data/time, file name, file size and transfer status need to log

Thanks
0
I have this rather simple shell script below and I see an error on line 8 below

What is wrong with my shell script?

set -x
for i
do
        echo $i
        outfile=$i_new
        echo $outfile
        cat $i | sed -e 's/STASIS //'   > $i_new
done
++ for i in '"$@"'
++ echo file1.xml
file1.xml
++ outfile=
++ echo

++ cat file1.xml
++ sed -e 's/STASIS //'
./removeStasis.sh: line 8: $i_new: ambiguous redirect


Here is my script:

set -v
set -x
for i
do
        echo $i
        outfile=$i_new
        echo $outfile
        cat $i | sed -e 's/STASIS //'   > $i_new
done
0
Hello,
with openldap you can define a max-password age: pwdMaxAge
Any ldap account that uses a password that was set before today-pwdMaxAge (in seconds) is considered expired.

Now on http://techadminblog.com/send-password-expiry-warning-openldap/

there is a script that can be run with crontab checking all ldap accounts and informing the affected users of an impending password expiry.

It checks if there are 3,2,1 today days left.

if [ "$DIFF" == `expr $MAXPWDAGE - 3` ]; then
 SUB="User $USERID password expire in 3 days"
 smail
 elif [ "$DIFF" == `expr $MAXPWDAGE - 2` ]; then
 SUB="User $USERID password expire in 2 days"
 smail
 elif [ "$DIFF" == `expr $MAXPWDAGE - 1` ]; then
 SUB="User $USERID password expire in 1 day"
 smail
 elif [ "$DIFF" == "$MAXPWDAGE" ]; then
 SUB="$USERID password will expire today at $EXTME UTC"

----
How can I change that part of the script  to inform the users that a password change is needed in less than 20 days, less than 10 days, today, or even has already expired?

does change "$DIFF" == `expr $MAXPWDAGE - 3` ->  "$DIFF" -lt  `expr $MAXPWDAGE - 20` the trick?

Reason we use openldap to handle external user accounts that are rarely used so informing the users that their pasword will expire in 3 days is too late - in most cases the password is often already expired when they call us about being unable to logon to our systems.

regards,
Tolomir
0
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.

PHP:-
<?php
session_start();
if(isset($_SESSION['username']))
{
$username=$_SESSION['username'];
$result = shell_exec('./get.sh >> 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

0
Hello,

  I would like to know if there is a way to create a Symlink-like file but with the difference that the file it points to gets executed when the link is read and the output is what I get from reading it.
  It should work on freebsd/linux.

Thanks

Best regards
0
Free Tool: SSL Checker
LVL 9
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.

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:

Hostname
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.
0
I have few excel and .rpt file which are updating daily basis, in my scenario i have to parse the files and some of the columns should be insert into MS access database. i am not sure how to start with. As per my manager i should use shell scripting to write the code but i am not sure which is the best way.

I need help in this any kind of help will be appreciated.
0
Hello Experts,

I have created an EFS Filesystem, I am trying to find a script which will give me the below

Input to script : EFS Filesystem ID
Output : {AZ targetIPAddress}

we dont have aws dns, so we are manually mounting using IP address...Here are the steps, I have...

1. The below command will give the Subnet and IP address
# $ aws efs describe-mount-targets --file-system-id fs-e10c82b2 --query 'MountTargets[*].[SubnetId,IpAddress]' --output text
OUTPUT : {SUBNET IPADDRESS}

2. The below command will give me AZ for the subnets
$ aws ec2 describe-subnets --subnet-ids subnet-9456320b --query 'Subnets[].AvailabilityZone' --output text
INPUT :SUBNET
OUTPUT : AVAILABILITY ZONE

How do I combine these 2 scripts to get
- AVAILABILITYZONE IPADDRESS

Please assist
0
Hi,

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"
0
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 abc-yyyymmdd.zip. 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.
0
Thank you for sharing this codes, By this code my password  not accepted so how do i proceed it. PS: May password contains % character. Like Ad%r99
0
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.

#!/bin/sh

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"
EOS
0
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  ))
0
Hello,
I have in a shell script, a variable that uses xmllint like this:

Xpath_querry = $ (xmllint --shell $ {xmlfile} << EOF
    Setrootns << EOF
    Xpath count (// defaultns: $ {parse_tag /} / defaultns: $ {tag}))

This worked but now, I have an EOF error in the console at run time.
Would anyone know another way to rewrite this variable (that the variable is used later in the script)?
0
Ready to get started with anonymous questions?
LVL 9
Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

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
0
I currently login to the time from website using the following script.


browser = webdriver.Chrome('E:/Shared Folders/Users/runnerjp/chromedriver/chromedriver.exe')
browser.get("https://www.timeform.com/horse-racing/account/sign-in?returnUrl=%2Fhorse-racing%2F") 
time.sleep(3)
username = browser.find_element_by_id("EmailAddress")
password = browser.find_element_by_id("Password")
username.send_keys("usr")
password.send_keys("pass")
login_attempt = browser.find_element_by_xpath("//input[@type='submit']")
time.sleep(3)
login_attempt.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?
0
Hi,

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.
 
Thanks
Abdul
0
Hi,
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.
global_index.js
index.js
0
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    10.172.0.0/22
            10.172.1.0/24 subnet
            10.172.2.0/24 subnet
            10.172.3.0/24 subnet
            10.172.4.0/24 subnet
client 2    10.173.0.0/22
client 3    10.174.0.0/22

            10.175.0.0/22  #Should give me this next available block

Open in new window

0
Hi,

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.
0

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.