LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-13-2018, 04:19 AM   #1
parpande
LQ Newbie
 
Registered: Apr 2018
Posts: 1

Rep: Reputation: Disabled
How to Collect Logs from My Script (Maybe Using File Descriptors)


Below is a part of my script . Whenever the script executes ‘ls -ld $dir1’ it throws a msg while script is in execution. Could someone let me know to avoid that message and could be collected separately via stderr or logs by using any of the filedescriptor.

echo -e “\nChecking if the directory $dir1 already exists\n”

ls -ld $dir1

if [ $? -eq 0 ]

then

echo -e “\nDirectory exists!!! Checking to verify if the same directory exists in /etc/fstab\n”

else

echo -e “\nCreating directory $dir1\n”; mkdir $dir1

echo -e “$dir1\t$ip1($per1,sync,$rperm2,no_subtree_check)” >> share

fi

done
 
Old 04-13-2018, 04:32 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 16,835

Rep: Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080
Welcome to LinuxQuestions.

Assuming you are using bash I would use a conditional expression instead of the ls command.
Code:
if [ -d $dir1 ]
then
  echo "Directory exists
fi
https://www.gnu.org/software/bash/ma...pressions.html
 
Old 04-13-2018, 05:49 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,438

Rep: Reputation: 1054Reputation: 1054Reputation: 1054Reputation: 1054Reputation: 1054Reputation: 1054Reputation: 1054Reputation: 1054
Code:
if [ -d "$1" ]; then
    ...exist...
else
    ... doesn't exist _or_ not directory...
fi
Edit: Oh, too late
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Back up logs file and create a script showing the backed up logs and the running logs Billy_6052 Programming 5 12-13-2014 02:32 AM
collect red hat linux error logs zhaoyy Red Hat 1 08-15-2012 07:48 AM
How i can to collect all logs of unix server? mousa535 Linux - General 1 12-26-2010 07:16 AM
USB stub driver to collect descriptors of all devices present on bus nimesh shah Linux - Software 1 10-18-2008 11:42 AM
to collect logs from xterm window. ponezhil Linux - Newbie 1 05-13-2008 09:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration