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

0
On Demand Webinar: Networking for the Cloud Era
LVL 9
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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
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
OS: AIX shell:ksh

i need a grep statement to give any  error for today's date and for specific time from a log file.

My grep statement should grep current date i.e. 7/19 and timing for 6 to 6:59 and finally for string as 'error' or 'Error'

e.g  log file content will be like

[7/19/17  6:01:26:611 CDT] XXXXX  error -911
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
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
Want Experts Exchange at your fingertips?
LVL 9
Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

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
We currently operate within a Citrix environment and publish a number of web applications by point to Internet Explorer with the corresponding website as the parameter.

We face an issue currently whereby if the browser is closed, the session remains active.

We need the session to logoff if the browser is closed.

With a previous version of IE (8 perhaps, but not entirely sure) we scripted this, however in current versions of IE this no longer works.

I guess a script that launches IE, and then monitors for its closure before issuing a logoff command would be ideal, but am open to alternative suggestions if there are better ways to achieve what we are looking for.
0
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
I heard iOS is tailored from FreeBSD so I'm hoping to be able to do something like
"ps -ef |grep email_client_process"
if it's not there, then restart it.

Reason is our MobileIron email+ client kept getting killed by iOS as iOS sees it
as a 3rd party/foreign process.

any chance of doing this on an MDM controlled device?
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
how to execute "at unix command" in remote server via SSH or any other mean (using shell script)
0
need to send html mail body as mail using shell script in AIX
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 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
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
Hi ,
 
Can someone help here in this script:-It is throwing error:-



ORACLE_HOME=/opt_local/oracle/product/V10.2.0;export ORACLE_HOME
export PATH=$PATH:$ORACLE_HOME/bin
sqlplus -s "crm702_data/crm702_data@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL = TCP)(HOST=ariel.kpno.be)(PORT=1510)))(CONNECT_DATA =(SID=EPNYPRD)))" << EOF
for reference_code in `cat Mark_Obsolete.txt | tr " " "\n"`
do
@Mark_Obsolete.sql $reference_code
done
EOF
echo "done"




graffias:> more Mark_Obsolete.txt
1000333 1009398 1028828


SP2-0734: unknown command beginning "for refere..." - rest of line ignored.
SP2-0223: No lines in SQL buffer.
SP2-0223: No lines in SQL buffer.
SP2-0042: unknown command "do" - rest of line ignored.
Enter value for 1: done : NOT A VALID SALES ORDER REFERENCE
done



Can some one give me a format where i read the text file and transalte all orders in new line and then my sql script will use argument one by one from that text file.
0
I am looking for a command that will tell me in the whole host if I have the rights to the entire file system , if any files have changed in the last one minute or 5 minutes

I thank you very very much in advance and will reward pts right away !!!!
0
I've never used Powershell to run scripts before so be gentle, this scripting stuff is very new to me :)

I just copied what I thought would be a very handy script from a Microsoft article that I saved as PatchScript.ps1, but when I try to run it in Powershell, I get the error:

File C:\1\patchscript.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
At line:1 char:21
+ c:\1\patchscript.ps1 <<<<
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException

I looked into signing and it seems like such a long winded process to go through just to run the occasional script I'm confident will be safe, so was wondering if there is an over-ride of some sort to run an occasional self created script?  

Or is there an easy way to temporarily disable the policy preventing the execution of scripts, and then re-enable that policy immediately afterwards to maintain the security that it provides?

Your help would be appreciated.
0
Hi Experts, how to pass (ignore) below line in regex. I'm  trying to achieve this in jenkins log parser plugin.

# Should pass
chmod: cannot access './config/temp_bkp_24072016/resources': Permission denied

# Should fail
chmod: cannot access './config/resources_bkp_24072016/resources': Permission denied

#regex rule. which I'm trying to handle above two scenario
warning /^(?!.*(temp_bkp))(.*Permission denied.*)$/

Open in new window



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.