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

I have one access_log under main folder and have to copy that access_log under another folder where external FTP Server can able to download the log automatically.

My Question is Access_log generated in server for Whole day but we need to have only access_log for 15minutes using diff command.

Please let me know the diff command to be used for changing filename automatically everytime once the diff checked between two files.
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 Experts,

I want to compare directories only on two servers, without files inside each directory.
I was hoping to get output telling me what directories are missing.

Below command works but doesn't tell that parent directory31 is missing on server1.
Is it possible to get just missing directories between two server paths without copying anything?

[sat@server directory]$ rsync -n -av --include='*/' --exclude='*' --delete /home/sat/directory/ sat@server1:/home/sat/directory/
sat@server1 password:
sending incremental file list
./
directory1/
directory1/directory2/
directory1/directory2/directory3/
directory11/
directory11/directory12/
directory11/directory12/directory13/
directory21/
directory21/directory22/
directory21/directory22/directory23/
directory31/
directory31/directory32/
directory31/directory32/directory33/
 
sent 385 bytes  received 63 bytes  179.20 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)
[sat@server directory]$

server output

[sat@server directory]$ pwd
/home/sat/directory
[sat@server directory]$
[sat@server directory]$
[sat@server directory]$ ll
total 16
drwxrwxr-x 3 sat sat 4096 Jul 12 14:32 directory1
drwxrwxr-x 3 sat sat 4096 Jul 12 14:33 directory11
drwxrwxr-x 3 sat sat 4096 Jul 12 14:33 directory21
drwxrwxr-x 3 sat sat 4096 Jul 12 14:37 directory31
[sat@server directory]$

server1 output

[sat@server1 directory]$ pwd
/home/sat/directory
[sat@server1 directory]$
[sat@server1 directory]$ ll
total…
0
Hi Experts,
pls refer this question. would like to extend bit further on masking the pwd values when we have more than one properties in a file.

https://www.experts-exchange.com/questions/29107089/Display-file-content-but-mask-password-value-in-bash.html
Solution from above question
cat /path/to/property//file|sed -e 's/db_password=.*/db_password=xxxxxxxxx/i'

Open in new window


could you pls help me how to mask two properties in single go please

hostname=server1
db_sid=oracledb
db_username=scott
db_passowrd=tiger
username_wls=weblogic
password_wls=welcome1
target_script_dir=/u01/app/oracle/scripts
target_db_client_home=/u01/app/oracle/db/client_1
0
I' am writing a shell code to email my audit file produced at solaris 5.10.

Please let me know the mailx code to send the html file content as the email body.
0
Hi Experts,
According to my work , iI have a java code which generate shell script for ftp files.
So in the code
ftp.append("cd /home/user/user output/files for June ");

Open in new window

But according to shell script , If folder name contains space, then either we need to keep complete path inside quotes or space we can replace with back slash
for eg
cd "/home/user/user output/files for June " 
or
cd /home/user/user\output/files\for\June

But in java , It is not allowing me to put both  back slash \ and " saying invalid escape sequence.
How can I resolve it?
Thanks in Advance Experts............
0
Hi Experts,

I have to write a script which first read filenames in a directory and according to the name it should run jar files.
for eg filenames are according to the month and year-----07-18-01.txt ,07-18-02.txt , 08-18-01.txt,-------- (month-year-randomnumbers.txt).

My script should read these filenames , If moth-year matches with current month-year.It should run a.jar
otherwise b.jar

Current month year ,I am giving as
date +%m-%y

Open in new window

If filename contains value of this , It should run a.jar
if not ,it should run b.jar

Could you please help me to solve it..
Thanks in Advance.
0
I was experimenting with bash file descriptors and such.  I found a function to return the first available file descriptor:
#!/bin/bash

function find_next_fd() {
    local fd=2 # start at 2 to skip stdin, stdout, stderr
    local max=$(ulimit -n) # man 1 bash
    local found=0 # a flag
    while ((++fd < max)); do
        # if the file descriptor does not exist, 
        # set found and break
        ! true <&$fd && found=$fd && break
    done 2>&- # dump the bad descriptor error
    echo fd = $fd, found = $found
    return $found
}

find_next_fd
echo $?

Open in new window


This works pretty well.  If I run with no other settings, I get 3.  After executing `exec 3>somefile`, this script returns 4.  Execute `exec 3>&-`, and I get 3 again.  I wanted to see what happens when it gets to the limit.  Instead of creating descriptors up to 1024, I just removed the "!" from the test, i.e., it would return the first used descriptor.  I was expecting "0", but was consistently receiving "10".  I added these two lines into the while loop:
        echo Checking $fd
        ls -al /proc/$$/fd

Open in new window


This is a sample return:
#> ./fd-test.sh
Checking 3
total 0
dr-x------ 2 root root  0 Jul  4 04:51 .
dr-xr-xr-x 9 root root  0 Jul  4 04:51 ..
lrwx------ 1 root root 64 Jul  4 04:51 0 -> /dev/pts/1
lrwx------ 1 root root 64 Jul  4 04:51 1 -> /dev/pts/1
lrwx------ 1 root root 64 Jul  4 04:51 10 -> /dev/pts/1
lr-x------ 1 root root 64 Jul  4 04:51 255 -> 

Open in new window

0
Mac OSX question

I have a large library of digital media. Most of it is kept "offline" but the library software I use (Plex) uses media files to build the library and so I need to use placeholder files.

Using 30 second "this file is archived" videos I can easily catalog offline movies in Plex. I "rsync" the directory structure without files and then "do cp" a placeholder into each movie directory and rename using the parent folder name.

For TV shows this isn't practical as there can be hundreds of episodes per show. I would like to know if there is a way to duplicate the folder/file structure of a tv show, with many episodes under a single folder, using the same placeholder file.

To reiterate, the ultimate goal is to take a placeholder file eg. "placeholder720p.mkv" and use this file to recreate the source directory with the same filenames. So in the end I will have a folder that looks identical to the source, but consists of this placeholder file duplicated over and over. Also, there are non-alphanumeric characters and spaces in the filenames to be duplicated.
0
Hello Experts,

Good Day...

I have a script which produces password protected  zip file in linux server..I write it using expect commands.

#!/usr/local/bin/expect -d -f
send "cd outputpath\r"
send "zip -e -rj OutputFileExtracted.zip /inputpath \r"
expect "Enter password:"
send "test\r"
set timeout 40
expect "Verify password:"
send "test\r"
set timeout 40
send"*#*"

Open in new window


But the above code is not producing any output.
When I m using the same commands (not expect commands ) in linux command prompt ,It is able to zip the files with password protected.
for eg :
cd outputpath
zip -e -rj OutputFileExtracted.zip /inputpath

Open in new window

then it asked for password
Enter password:

Open in new window

User input
Verify password:

Open in new window

again user input

Any one can tell me what is wrong with the expect commands? I tried with
spawn zip -e -rj OutputFileExtracted.zip /inputpath

Open in new window

in script..That also didnt give me output.

Thanks in Advance.
0
Hi Experts,

As part of my work I have following folder structure in linux server,

folders as 0,1,2,3,4,...9 and each folder contains subfolders as 0,1,2,3,4,...9.. After my job run ,These subfolders will have some pdf files..Once FTP is done from this server to another,I have to delete pdf files from each subfolders.

But script should not delete folders and subfolders.It should delete only the documents inside it.

I tried with rm command..But it didnt work.Do I need to use any loop?

Any Expert can help me on this?
1
Cloud Class® Course: Microsoft Windows 7 Basic
LVL 12
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

difference between double and single quote in unix vs windows word document


1.
grep ‘Bean’ abc_1.log.20180627 //i am able to type this angular single quote in windows laptop in a word pad to save all commands to copy paste to unix box

2.
grep 'Bean' abc_1.log.20180627//why i cannot type this straight single quote character on windows laptop in a word pad to save all commands to copy paste to unix box?
3.
grep "Bean" abc_1.log.20180627


when i type below in word document of windows its shows as

grep ‘Bean’ abc_1.log.20180627
when i type below in putty/mputty of windows its shows as
grep 'Bean' abc_1.log.20180627



my purpose is to save all these unix queries to a word document so that next time i can copy paste from word document to putty and execute them without any tweaking to queries.

Please advise
grepCommands.png
0
I am getting hung up on the quotations syntax in a Linux bash Shell Script:

PURGE_ASOF=$(date -d '3 years ago')

echo "$(date +'MyHardDate is %F' -d '2011-04-05')"

echo "$(date +'MyVarDate is %F' -d $PURGE_ASOF)"



The first echo works well, but the second one crashes since the resultant date contains whitespace.


How can I put double-quotes inside the double-quotes to resolve my variable into a single string instead of multiple strings separated by whitespace ?

Thanks for any advice or assistance.
0
Hi Experts,

I have shell script for zipping files
zip -j output.zip filepath;

Open in new window


I need to encrypt this zip file.So I modified like below
zip -e -j output.zip filepath;

Open in new window


But we need to provide expect commands also right.

Enter password:
Verify password:

How can I integrate expect commands along with this?Shall I need to put extra text file for expect command or in the same script can we add expect commands?

Any help regarding this would be highlight appreciable.
0
I have a bash file to execute a join query against a sqlite 3 db.
#!/bin/bash
sqlite3  /test.db  "select * from report_details inner join reports r   on rd.id =r.id inner join ( ...) derivedquery  dr on r.id=dr.id;"   > testoutput.txt

I get an error sql statement missing ;
It does not throw an error if the sql is a simple join fitting onto one line .
0
Hi Experts,

Greetings...

I have to move files from different folder to other folders in between linux servers using batch script.

Script will be present  in the first server

output server name : name
username : uname
password:paswrd

files are present inside ---- inputpath/5/6/abcde.pdf , inputpath/5/7/cdesf.pdf ,.........etc
OutputFile path in second server=     outputpath/5/6/abcde.pdf ,outputpath/5/7/cdesf.pdf,................

Any help regarding this would be highly appreciated
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
Hi Experts,

I have shell scripts named as a.sh,b.sh ,c.sh and one jar file also.

Have to call these all  files  from a single sh file (main.sh ) by series not parallel.

Any help regarding this would he helpful.
0
Hi All,

Fetching the mail body content from FND_NEW_MESSAGES in Oracle apps and writing the text in a file(.txt) and mailing it to the recipient in Shell Script using mailx command.

Problem is Line breaks(\n\r)  are not getting transformed to the Mail body in the mail.(outlook).


How to avoid newline breaks getting lost while mailing from shell script.
0
Hi All,
Pls may I know that
How to show the customized message box when opening the folder in map networks drive or explore for some specific users ??? Appreciate that someone can help me.

Regards,
Thu zar
0
Keep up with what's happening at Experts Exchange!
LVL 12
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

1. Can someone explain me if there is any changes in .cloginrc file, I need to run the rancid-cvs and rancid-run,
2. When i am trying to login i can see that the username is not pulling from what is there in .cloginrc.

For Eg:
(Under my clogin file)
I have mentioned
add user 1x.x.x User1
add password 1x.x.x       {password}
add method 1x.x.x telnet ssh

But when i am trying to login, i can see that username is in rancid. I am not sure why its happening. And to make sure that if try firewall login or normal login, its going with actual username only
0
I have a CVS file with thousands of lines and columns. I need to focus on column AM named or any column named  "EA-domain_list" in that row, I have several domains that are separated by commas in there.

Is there a way via perl, or some type of script that will feed this spreadsheet named master.csv in and take all the EA-domain_list that are in commas, and make new columns for each domain. Basically for example in summary

you look in the attached spreadsheet and look an AM you see mobi.sark.net, ne.sark.net,sark123.test.com I need what ever is in there to strip each domain into a new column like AS would be called EA-domain_list an in there would have ne.sark.net, the another one row AT would have sark123.test.com. Keep in mind some times there are 20 of  then in there. So then I would like to spit out a new file called adjusted_domain_list.csv

Also, I am sorry I didn't mention previously that I am using a Macbook
Example-Master.csv
0
Need your help to resolve the below query.  
I want to sum up the values for column4,column6,column7, column8,column10,column11 if value in column1 is duplicate.  
Also need to make duplicate rows as single row in output file i.e (column3 can have any of value from duplicates values in output file of column3 ex : can contain either abcd123,qwert or 345rty).   Also need to append all duplicate values of column3 of input file in column 12 of output file expect the one which we have already stored in column3 of output file (ex. column12 of output file can contain only in form qwert^345rty if value abcd123 is used in column 3 of outputfile

input file

   
    a|b|c|d|e|f|g|h|i|j|k
IN27201800024099|a|abcd123|2.01|ad|5|56|6|rr|1|2
IN27201800023963|b|zxcv123|3|rt|67|6|61|ty|6|3
IN27201800024099|a||qwert|4|ad|5|6|1|rr|7.45|4
IN27201800024099|a|345rty|5|ad|5|6|1|rr|8|4
IN27201800023963|b|1234ret|7|rt|5|5|1|ty|56|5
IN27201800024098|f|qazxswe|80|ty|6|6|1|4rght|765|5

Open in new window


output file

   
 a|b|c|d|e|f|g|h|i|j|k|l
IN27201800024099|a|abcd123|11.01|ad|15|68|8|rr|16.45|10|qwert^345rty
IN27201800023963|b|1234ret|10|rt|72|11|62|ty|62|8|zxcv123
IN27201800024098|f|qazxswe|80|ty|6|6|1|4rght|765|5|qazxswe

Open in new window


Tried below code, but it is not working and also no clue how to complete the code to get correct output

    awk 'BEGIN {FS=OFS="|"} FNR==1 {a[$1]+= (f4[key]+=$4;f6[key]+=$6;f7[key]+=$7;f8[key]+=$8;f10[key]+=$10;f11[key]+=$11;)} input.txt > output.txt

Open in new window

0
How can I pull the short name of user 502 (on a Mac) in a script to set the computer name?  For example, one laptop has user 502 w/ short name of msmith, I need msmith to be used in the following where $502-short-name would be msmith.  I tried the id command, but it returns too much info.


sudo scutil --set ComputerName-$502-short-name
sudo scutil --set LocalHostName $502-short-name
dscacheutil -flushcache

thanks
0
I have a unix shell script which is used to connect to oracle db. But the concern is the script has clear text password Is there a way not to have clear text password while connecting to oracle schema.
0
Need help creating a GPO, linking it to the domain, and setting policies

Hello

We are an MSP and have about 20 client locations that we manage and would like to create a Powershell script to create and configure a Audit / Account / Password policy for all of our clients using the following settings:

[Unicode]
Unicode=yes
[Version]
signature="$CHICAGO$"
Revision=1
[Event Audit]
AuditPolicyChange = 1
AuditAccountManage = 3
AuditAccountLogon = 3
[System Access]
MinimumPasswordAge = 0
MaximumPasswordAge = 90
MinimumPasswordLength = 8
PasswordComplexity = 1
PasswordHistorySize = 10
LockoutBadCount = 5
ResetLockoutCount = 15
LockoutDuration = 15
ClearTextPassword = 0
[Registry Values]

I have searched as best as I could for how to implement this but have not been able to find anything.

Any help with this would be great.

I have also attached a screen shot of the report as well.
Audit-Password-Account_Policy_Report.jpg
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.