Shell Scripting

10K

Solutions

6K

Contributors

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 guys

So I got some help from EE experts to run a command in Exchange shell to export all mailbox statistics/data.

One of the important things is for me to work out the LastLoggedOnTime so that I can segregate the oldest mailboxes from the actively used ones.

I ran a tool called Inactive Users Tool by Solarwinds and exported it. When I compare the last logged on time of one user from the Exchange shell formula to the data exported from the Solarwinds one, they are different. I have many users who have not logged on for years, but somehow are showing as two days ago in the Shell statistics.

Perhaps the Solarwinds tool is using the Inactive users by looking at a different attribute?


Any ideas on why that would be?

Thanks for helping
Yashy
0
Upgrade your Question Security!
LVL 12
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Hi guys

We have Exchange 2010 SP3 and I was hoping you could help me pull out an Exchange report that will put everything below into separate columns in an Excel file. It can be ascending or descending based on mailbox size:

FirstName
SecondName
DisplayName

AccountName or Alias
MailboxSize (GB)
LastLoggedOnTime
Mailbox Database Name

Can you help me with this?

Thanks for helping
Yashy
0
Hi,

I would like to request an assistant.

I would like to make a redirect using .htaccess .

The condition that i would like to combined are as follows :

1. redirect any access from /supporttickets.php to https://support.domain.com

2. redirect any access from  /submitticket.php to  https://support.domain.com/Tickets/Submit

3. redirect any access from   /contact.php to https://www.domain.com/contact.php

4. redirect any access to "billing" folder to https://billing.domain.com

5. IGNORE all above rules if the access file are "fpx_indirectcallback.php" or "fpx_directcallback.php"


Appreciates anybody assistant on this issue.
0
Hi guys

I'm trying to output mailbox sizes, account names, lastlogon time using Exchange Management shell by running the below:

Get-MailboxStatistics  -Server “ServerName” | Select DisplayName, sAMAccountName, LastLoggedOnUserAccount, ItemCount, TotalItemSize, LastLogonTime,  | Sort-Object TotalItemSize -Descending | Export-CSV c:\Folder Name\Filename.csv

I input all of the details where the quotes are, but then for some reason the SamAccountName section is always blank. Can someone help me with that please so that I can have the account names exported also?

Thanks for helping
Yashy
0
I need to replace a line in a configuration file and want to make sure it's done safely since it needs to be done on several systems.

The line in the file is:
*.emerg                                                 *

Open in new window

I want to replace the end of line * on only lines that start with *.emerg with :omusrmsg:* so it looks like this:
*.emerg                                                 :omusrmsg:*

Open in new window

This sed command seems to work, but was curious if there was a more full proof way to do it:
sed -i '/^\*.emerg/s/\*$/:omusrmsg:*/' config.conf

Open in new window

0
Hi experts,
Could you advice the best way to achieve below scenario in linux/bash env please

1. Have a server/host names in a comma separated list. E.g
server1,server2,server3,server4,server5

Open in new window


2. Have a generic template file like below
host: server_token
remote: true
port: 7001

Open in new window


3. Need create server specific file from template using automation/bash. So we will have 5 files as an outcome. E.g
file1
host: server1
remote: true
port: 7001

Open in new window


file2
host: server2
remote: true
port: 7001

Open in new window


file3
host: server3
remote: true
port: 7001

Open in new window


file4
host: server4
remote: true
port: 7001

Open in new window


file5
host: server5
remote: true
port: 7001

Open in new window

0
Hi Experts,
As part of my automated verification task using ssh on remote server

1. Would like to (cat) display the content of a property file on the linux server.
2. So we dont login to each target server and check the value.
3. Instead by executing ssh user@server1 "cat /path/to/property/file" would display the content.
4. Since i also have password in the property file...would like to mask it with 'xxxxxxxx' e.g not showing the actual value.

pls help how to show the content of a file but mask only the password value

Sample file content
hostname=server1
db_sid=oracledb
db_username=scott
db_passowrd=tiger
target_script_dir=/u01/app/oracle/scripts
target_db_client_home=/u01/app/oracle/db/client_1

Open in new window



Expected output display
hostname=server1
db_sid=oracledb
db_username=scott
db_passowrd=xxxxxx
target_script_dir=/u01/app/oracle/scripts
target_db_client_home=/u01/app/oracle/db/client_1

Open in new window

0
Hello Expert,

I want to read o/p from a java process using following cron job, when i tried to use below script its o/p not written into the ScheduleDevice.log.
Could you please guide me why it throwing empty o/p  inside log.

Script  /usr/local/cronjobs/Java-Files/ScheduleDevice.sh
---------
#!/bin/bash

java -cp ".:mysql-connector (1).jar:org.eclipse.paho.client.mqttv3-1.1.0.jar" ScheduleDevice

the_output=`java -cp ".:mysql-connector (1).jar:org.eclipse.paho.client.mqttv3-1.1.0.jar" ScheduleDevice`

echo "$the_output"

while read line; do echo "LINE: '${line}'"; done < <(echo "$the_output")

crontab -l
--------------
*/5 * * * * /usr/local/cronjobs/Java-Files/ScheduleDevice.sh >> /usr/local/cronjobs/Java-Files/ScheduleDevice.log


ScheduleDevice.log  file 0/p

LINE: ''
The Java O/P is
Script Executed Successfully at Fri Jun 29 20:50:02 IST 2018

LINE: ''


Normal o/p when executing using below script in ad-hoc

[root@vps1 Java-Files]# ./ScheduleDevice.sh

The Java O/P is
Script Executed Successfully at Fri Jun 29 20:51:56 IST 2018

Before start of all threads
2018-06-29
20:51
List of pendingSchedules
Finished all threads
Finished all threads
LINE: 'Before start of all threads'
LINE: '2018-06-29'
LINE: '20:51'
LINE: 'List of pendingSchedules'
LINE: 'Finished all threads'
LINE: 'Finished all threads'
0
This is using a SuSE Enterprise Linux 11 SP3 server. This is such a bash shell script running once per day. Please see the script contents as follows,

#!/bin/bash
################################################################
# Purpose: abc300 backup of new images (<2days) from the various users data dir
# Background:
# 1. script searches new files under slw, apis, edslw for new files
# 2. script creates the dir struct needed for each file
# 3. script calculates the last-backup-till-now-in-days to backup
# 4. script calls NBU to do a client-initiated backup
# 5. if backup is good, the holding dir is removed
# 6. if backup is bad, the holding dir is kept for the next backup cycle
# Dependancies:
# 1. /usr/openv/netbackup/bin/bpend_notify.LINUX_ANS.sh            <-- NBU post-backup job
# 2. THIS SCRIPT MUST NOT CROSS THE DAY !!! ( enforced to run during offc hours in this script )
# Changes:
#
#
#
#################################################################
#set -x

## enforce the limitations to office hours
## backup that crosses the day will have a problem
HOUR=`date +"%H"`
#if [ $HOUR -lt 8 -o $HOUR -ge 17 ]; then
#      logger "$0 Run backup only during office hours ...."            ##exit quitely
#      exit 1
#fi


## specs
DATE=`date +"%Y%m%d"`
BASEDIR=/backup/ansv1
LOGDIR=$BASEDIR/CBS_BACKUP
BKUPDIR=$BASEDIR/holding
USERLIST="slw apis edslw edslw"
DAYS2KEEP=0                               ### script generated, do not change
BUFFER4ERR=10800                    ### …
0
Hi Experts,

Good Day..

 I have a shell script which moves files from one linux server to another.

As per the requirement , Output path folder contains space in between folder name ..eg ----outputserver/file out/date on file/.

According to my knowledge , If path contains space in between,command wont execute successfully.

Can anyone help on this how to proceed further..Is there anyway to give path with space like mentioned above.
0
Cloud Class® Course: CompTIA Cloud+
LVL 12
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Hello Expert,

Could anybody please guide me what does the below command means and how it works .

# Set the environmental file/configuration file
. $(cut -d/ -f1-3 <<<"${PWD}")/bin/IDRP_Init.sh

Thanks in Advance.
0
Hi Expert,

I'm Looking for MySql DB Backup process in a Linux Machine which i want to schedule by crontab in a with every 3 days window duration.

Could anybody can guide me for basic shell steps and the back up steps .

Please let me know if there any additional information .

Thanks in Advance!
0
I followed a simple tutorial on how to schedule console applications (exe ) on windows scheduler. I came across "Puppet" and how it can be used to manage/configure such applications.
what is puppet and how can it be used  ?
0
Below is a sample of data in TABLE_FORMAT tables. I want to Compare the actual table names in SCOTT schema with the data in  TABLE_FORMAT.  Insert into TEST123 table the names of tables not meeting the naming convention in TABLE_FORMAT table. I  need help please.

The first query return a roll because  "SCR_00083_UB_ALL_FNL_2" fall within the naming format. The second query didn't return any row because "SCR_00083_UB_ALL_FNL_2t" doesn't falls within the naming format. I want to insert the name of tables that do not fall in the naming conversion.

 select * from (
select UPPER(TABLE_FORMAT) table_format, upper(replace(replace(replace(replace(table_format,'${TB_STAMP}','%'),'${SCENARIO}','%'),'${END_DATE}','%'),'_','\_')) new_table_format from AR9_EIP_TABLES_TEMPLATE) a
  2    3    where 'SCR_00083_UB_ALL_FNL_2' like new_table_format escape '\'
  4  ;

TABLE_FORMAT                             NEW_TABLE_FORMAT
---------------------------------------- ----------------------------------------
SCR_${TB_STAMP}_UB_ALL_FNL_2             SCR\_%\_UB\_ALL\_FNL\_2


select * from (
  2  select UPPER(TABLE_FORMAT) table_format, upper(replace(replace(replace(replace(table_format,'${TB_STAMP}','%'),'${SCENARIO}','%'),'${END_DATE}','%'),'_','\_')) new_table_format from AR9_EIP_TABLES_TEMPLATE) a
  3    where 'SCR_00083_UB_ALL_FNL_2t' like new_table_format escape '\';

no rows selected
0
Hi Team,

I have an procedure called get_employeename (p_empid number , p_name out varchar2) .

Iam invoking this sp from unix script , I need to capture the p_name into a unix shell variable , iam trying the below code but gives an error when i execute it.
 
empid =101
ename ='  '
sqlplus -S hr/orcl@payroll << EOF
set verify off
set echo off
set trim off
set term off
set timing off
exec get_employeename($empid,$ename);

EOF

Any help is really appreciated.
0
I am looking for a script that can tell me which components of office 2016 are installed.

To give you a better idea: if you open office setup on a pc that has office installed and select add/remove features, it will display a list of components that are present with some left out components X'ed out. That's what script output I would like to see.

be so kind to test your script with office 2016 standard (volume license) if possible. In another forum, I was already provided with this script, wich for some reason does only work on click2run office:
Add-Type –MemberDefinition '
 [DllImport("msi", CharSet = CharSet.Unicode)]public static extern uint MsiEnumFeatures(string szProduct,uint iFeatureIndex, string lpFeatureBuf, string lpParentBuf);
 [DllImport("msi", CharSet = CharSet.Unicode)]public static extern int MsiQueryFeatureState(string szProduct,string szFeature);
' -name "tools" -namespace MSI -EA SilentlyContinue
$result = 0
$cnt = 0
$GUID = '{90160000-008C-0000-0000-0000000FF1CE}'
while($result -ne 259){
    $id = ' '*39
    $parent = ' '*39
    $result = [MSI.tools]::MsiEnumFeatures($GUID,$cnt,$id,$parent)
    if ([MSI.tools]::MsiQueryFeatureState($GUID,$id) -eq 3){
        $id.trim()
    }
    $cnt++
}

Open in new window

0
Hi,

I have a text file where I want to combine the first and second row into one row. How do I do it using the
Do Until objFile.AtEndOfStream
Loop



Thanks
SampleData.txt
what-is-needed.png
0
I am trying to figure out how to ping a remote hostname and return only the IP address and store it into a text file.

Could someone help me out? I really appreciate your help in advance.
0
This works:

do shell script "cURL -f http://mydomain/myfile.txt -o ~/Library/'Group Containers'/UBF8T346G9.Office/myFile.txt"

Open in new window

But extending the target path to include a second quoted folder fails:

do shell script "cURL -f http://mydomain/myfile.txt -o ~/Library/'Group Containers'/UBF8T346G9.Office/'User Content'/myFile.txt"

Open in new window

It raises an err:

Warning: Failed to create the file /Users/[username]/Library/Group

And in both cases, wrapping the full path in single quotes also fails at the same "Group" part of the path, eg:

do shell script "cURL -f http://mydomain/myfile.txt -o '~/Library/Group Containers/UBF8T346G9.Office/myFile.txt'"

Open in new window

What am I doing wrong?
0
Cloud Class® Course: CompTIA Healthcare IT Tech
LVL 12
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Hi, for a reason or another any new DFS I'm creating can be mapped as usual, but it's not displayed for everyone.  All users have the same permissions on the NTFS and DFS shares.  

Not matter how (GPO or manually in shell) it's done it's not visible.   When I use net use x: \\domain.com\dfs-drive /y  I don't get an error, it's successful but the DFS share is not visible.  

When I map an DFS that has been created before this issue I have not problem.  All DFS have been created on the same DC, same security, same NFTS, same servers.  

Thank you
0
What VBA would I use that would download a file, but before doing so validate the file can be downloaded before attempting the pull. If possible please try to do this without using On ERROR. I'm trying to see if there is a solid way to check if a file can be downloaded without attempting the download first.

EXAMPLE
  • In the link above it would validate the file can be downloaded before attempting the download. If for any reason the file could not be downloaded a message box would appear stating "The file can not be pulled. The link may have changed."

EXTRA NOTES
  • I may have seen someone try to do this using Dos/Shell but couldn't get it to work at the time and don't remember where it is at.
0
I wrote the following script to send me the names of new users added to AD in the last day. It works fine as long as there was only one user added.

If none were added,  I get this:
Send-MailMessage : Cannot validate argument on parameter 'Body'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

If multiple were added, I get this:
Send-MailMessage : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Body'. Specified method is not supported.

If only one were added, I get an email that displays the same stuff you'd get if you just had this as your script:
$When = ((Get-Date).AddDays(-1)).Date
Get-ADUser -Filter {whenCreated -ge $When} -Properties whenCreated

(though all I really want is the Distinguished Name.

Could someone please help me update this script so that:
1) If no users were added, I just get an e-mail saying no new users in the body.
2) If one, or more users were added, I just get a list of their Distinguished Names in the body of the email.

Here's the script as it stands now:
$When = ((Get-Date).AddDays(-1)).Date
$body1 = Get-ADUser -Filter {whenCreated -ge $When} -Properties whenCreated
$Subject = "New Users Added in Last Day"


$AdminName = "me@me.com"
$Pass = Get-Content "\\mypath\cred.txt" | ConvertTo-SecureString
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $AdminName, $Pass

Send-MailMessage -To …
0
How can I change the below via an
Exchange Management Shell script so
Test #2 updates the same C:\.... location
that Test #1 does when I force updates ?
---------------------------------------------------------------
Test #1
  4am automatic update location
  ** C:\Program Files\Microsoft\Exchange Server\V14\ExchangeOAB
---------------------------------------------------------------
Test #2
  Manual "ANYTIME" update location
  ** C:\Program Files\Microsoft\Exchange Server\V14\ClientAccess\OAB
1
Hi

I need a script in bash. Which will inform me about new files in the directory. I am new in scripting that is why cant build script properly.

I think i can do this via "if then"  ow with while.

Case like this.
Somedays in the month it will be uploaded some files to the directory. After adding new files, i want to script notify me that new files added successfully.
0
Dear experts,

I am a chartered accountant, CIMA and CFA.

I have a lot of experience in writing excel formulae (the entire credit goes to this forum, thank you experts).

I now want to pursue Financial Engineering.

I am learning C, C++ now. Once I become well versed with these two languages, I will move to learning Python.

Now from robustness, depth and FE requirement is Python better or MATLAB

I am not sure I have the bandwidth to complete/learn both.

Till date I have been learning C and I did not struggle to pick up the synatax or logic.

Kindly advice.
0

Shell Scripting

10K

Solutions

6K

Contributors

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.