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
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
11-23-2008, 04:03 AM
#1
Member
Registered: Jul 2005
Location: U.A.E
Distribution: FreeBSD,Fedora,Solaris,AIX
Posts: 168
Rep:
bash: passing asterisk to variable command
Hello, I want to pass asterisk to a variable:
Code:
#!/bin/bash
log=`cat /etc/httpd/conf/httpd.conf | grep ErrorLog | grep -v "#"| awk '{print $3}'`
ls -l $log*
i know it will work if i quote the variable "", but the variable is a command it will not work if i quote it.
any idea!
11-23-2008, 04:58 AM
#2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
I'm not grasping what you are doing...
The first statement assigns <<something>> to the variable named "log". What is the second statement supposed to do?
If you are trying to add a literal "*" to the contents of log, have you tried escaping it?
ls -l $log\*
ls -l stuff* ##lists the contents of all directories with names beginning with "stuff"
ls -l stuff\* ##lists the contents of the directory named literally "stuff*"
11-23-2008, 05:20 AM
#3
Member
Registered: Jul 2005
Location: U.A.E
Distribution: FreeBSD,Fedora,Solaris,AIX
Posts: 168
Original Poster
Rep:
Hello, i escape the asterisk with slash but didnt work.
Quote:
bash-3.00# ./script.sh
ls: 0653-341 The file /var/logs/error_log does not exist.
ls: 0653-341 The file /var/logs/error_log does not exist.
ls: 0653-341 The file /var/logs/error_log* does not exist.
it should give me:
Quote:
bash-3.00# ls -l /var/logs/error_log*
-rw-rw-r-- 1 apache apache 296 Aug 20 17:39 /var/logs/error_log.1219233600
-rw-r--r-- 1 apache apache 296 Aug 28 14:55 /var/logs/error_log.1219881600
-rw-r--r-- 1 apache apache 1111 Nov 08 15:42 /var/logs/error_log.1226102400
-rw-r--r-- 1 apache apache 370 Nov 10 09:14 /var/logs/error_log.1226275200
-rw-r--r-- 1 apache apache 592 Nov 12 15:50 /var/logs/error_log.1226448000
bash-3.00#
11-23-2008, 05:33 AM
#4
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
Hmmmmm.....back to my original question: What are you trying to do?
11-23-2008, 05:37 AM
#5
Member
Registered: Jul 2005
Location: U.A.E
Distribution: FreeBSD,Fedora,Solaris,AIX
Posts: 168
Original Poster
Rep:
I modify a script to audit apache config on AIX
this is the script:
Code:
#! /bin/bash
ps -ef | grep 'httpd' | cut -d " " -f 1 | grep -v 'root' | sed -n 1p >> webuseracct.txt
Path=`ps -ef | grep 'httpd' | sed -n 1p | awk '{print $11}'`
find $Path -type f -name httpd.conf >> httpd.txt
find $Path -type f -name *.conf >> httpd.txt
file1=`cat webuseracct.txt`
file2=`cat httpd.txt`
exec > apache_output.txt
echo File Security
echo =============
echo
echo "APC_01 - Weak permissions on files in Document Root"
echo ---------------------------------------------------
echo
DocRoot=`cat $file2 | grep DocumentRoot | grep -v "#"| awk '{print $2}'|sed 's/"//g'`
ls -dl $DocRoot
echo
echo "APC_02 - Weak permissions on Server Configuration files"
echo -------------------------------------------------------
echo
ls -l $file2
echo
echo "APC_03 - Weak permissions on log files"
echo --------------------------------------
echo
log=`cat $file2 | grep ErrorLog | grep -v "#"| awk '{print $3}'`
echo
ls -l $log*
echo
echo Logging and Server Information Handling
echo =======================================
echo
echo "APC_04 - Server Version Information Parameters are turned on"
echo ------------------------------------------------------------
echo
cat $file2 | grep -w ServerTokens | grep -v "#"
cat $file2 | grep ServerSignature | grep -v "#"
echo
echo "APC_05 - Logging directives not configured securely"
echo ------------------------------------------
echo
cat $file2 | grep LogLevel | grep -v "#"
cat $file2 | grep ErrorLog | grep -v "#"
cat $file2 | grep CustomLog | grep -v "#"
cat $file2 | grep LogFormat | grep combined | grep -v "#"
echo
echo Directory Access Permissions
echo ============================
echo
echo "APC_06 - Insecure directory access permissions"
echo --------------------------------------------------
echo
cat $file2 | grep Options | grep -v "#"
echo
echo "APC_07 - cgi-bin directory is not disabled"
echo ------------------------------------------
echo
cat $file2 | grep -w cgi-bin | grep -v "#"
echo
echo "APC_08 - Insecure User Oriented Directives"
echo ------------------------------------------
echo
cat $file2 | fgrep -w User | grep -v "#"
cat $file2 | fgrep -w Group | grep -v "#"
echo
echo
echo Denial of Service Protection
echo ============================
echo
echo "APC_09 - High timeout value"
echo ---------------------------
echo
cat $file2 | grep -w Timeout | grep -v "#"
echo
echo "APC_10 - Keep Alive setting not configured"
echo ------------------------------------------
echo
cat $file2 | grep -w KeepAlive | grep -v "#"
echo
echo "APC_11 - Keep Alive Timeout setting not configured"
echo --------------------------------------------------
echo
cat $file2 | grep -w KeepAliveTimeout | grep -v "#"
echo
echo "APC_12 - MaxKeepAliveRequests Parameter not set"
echo -----------------------------------------------
echo
cat $file2 | grep -w MaxKeepAliveRequests | grep -v "#"
echo
echo "APC_13 - StartServers Parameter not set"
echo ---------------------------------------
echo
cat $file2 | grep -w StartServers | grep -v "#"
echo
echo "APC_14 - MinSpareServers Parameter not set"
echo ------------------------------------------
echo
cat $file2 | grep -w MinSpareServers | grep -v "#"
echo
echo "APC_15 - MaxSpareServers Parameter not set"
echo ------------------------------------------
echo
cat $file2 | grep -w MaxSpareServers | grep -v "#"
echo
echo "APC_16 - MaxClients Parameter not set"
echo -------------------------------------
echo
cat $file2 | grep -w MaxClients | grep -v "#"
echo
echo Other Checks
echo ============
echo
echo "APC_17 - Web User Account not Locked Down"
echo -----------------------------------------
echo
cat /etc/passwd | grep $file1
echo
echo
echo "APC_18 - Non Essentail Modules are not removed"
echo ----------------------------------------------
echo
cat $file2 | grep -w LoadModule | grep -v "#"
echo
echo "APC_19 - Mod_Security module not installed"
echo ------------------------------------------
echo
cat $file2 | grep mod_security.so | grep -v "#"
echo
echo "APC_20 - HTTP Methods not limited"
echo ---------------------------------
echo
cat $file2 | grep LimitExcept | grep -v "#"
echo
echo "APC_21 - HTTP method TRACE not disabled"
echo ---------------------------------------
echo
cat $file2 | grep Rewrite | grep -v "#"
echo
echo "APC_22 - Buffer overflow protection not configured"
echo --------------------------------------------------
echo
cat $file2 | grep LimitRequest | grep -v "#"
echo
echo "APC_23 - Insecure Version of Apache used"
echo --------------------------------------------------
version=`ps -ef | grep 'httpd' | sed -n 1p | awk '{print $9}'`
$version -v
echo
echo
rm webuseracct.txt
rm httpd.txt
echo
echo ---------------End of output------------------
11-23-2008, 05:53 AM
#6
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
Sorry, that does not tell me anything......I'm quite elderly, and have a limited attention span. Going back to your original post, I simply need to know what "ls -l $log*" is supposed to do (in the context of the problem you are trying to solve.)
11-23-2008, 06:04 AM
#7
Member
Registered: Jul 2005
Location: U.A.E
Distribution: FreeBSD,Fedora,Solaris,AIX
Posts: 168
Original Poster
Rep:
Hello,
this line will grep the apache error_log path
Quote:
log=`cat /etc/httpd/conf/httpd.conf | grep ErrorLog | grep -v "#"| awk '{print $3}'`
in apache httpd.conf, this is the line the variable $log should grep:
Quote:
ErrorLog "|/usr/bin/rotatelogs /var/logs/error_log 43200"
this is $log output:
and this suppose to show all the error_logs files (the rotated files)
this should be the output of "ls -l $log*"
Quote:
-rw-rw-r-- 1 apache apache 296 Aug 20 17:39 /var/logs/error_log.1219233600
-rw-r--r-- 1 apache apache 296 Aug 28 14:55 /var/logs/error_log.1219881600
-rw-r--r-- 1 apache apache 1111 Nov 08 15:42 /var/logs/error_log.1226102400
-rw-r--r-- 1 apache apache 370 Nov 10 09:14 /var/logs/error_log.1226275200
-rw-r--r-- 1 apache apache 592 Nov 12 15:50 /var/logs/error_log.1226448000
my question is how to make the asterisk work with variable $log, it work fine if i put $log as:
Quote:
log="/var/logs/error_log"
ls -l $log*
11-23-2008, 06:17 AM
#8
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
The line "ls -l $log*" doesn't pass anything to a variable.
If you need to separate the part that is a variable name from what follows, put the
variable in brackets:
ls -l ${log}*
Since this is a script, you might want to include the full path to the ls command so that
you don't run an alias instead.
Check that the value of $log is what you think it is.
11-23-2008, 06:25 AM
#9
Member
Registered: Jul 2005
Location: U.A.E
Distribution: FreeBSD,Fedora,Solaris,AIX
Posts: 168
Original Poster
Rep:
ls -l ${log}* didnt work, i wont to use this script on many AIX systems and the apache config for them is different.
11-23-2008, 07:22 AM
#10
LQ Guru
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Sorry, but I just tried this and it works fine for me:
Code:
# in script
log=/var/log/rkhunter
ls -l $log*
# ouput
-rw------- 1 root root 76632 2008-08-24 14:59 /var/log/rkhunter.log
-rw------- 1 root root 3739 2008-08-24 14:56 /var/log/rkhunter.log.old
I don't know why it doesn't work for ya.
11-23-2008, 07:33 AM
#11
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
Creak, squeek, groooooooooan....
(sound of brain trying to figure this out.......)
I made five directories--dir1 thru dir5. In each one, I put a file (in dir1: file1, etc.)
Code:
[mherring@Ath ~]$ name=dir
[mherring@Ath ~]$ ls $name*
dir1:
file1
dir2:
file2
dir3:
file3
dir4:
file4
dir5:
file5
This seems to work as one would expect.
11-23-2008, 07:45 AM
#12
Member
Registered: Sep 2006
Location: Canada
Distribution: Gentoo
Posts: 702
Rep:
If you add an echo you can see what is being resolved as $log:
Code:
#!/bin/bash
log=`cat /etc/httpd/conf/httpd.conf | grep ErrorLog | grep -v "#"| awk '{print $3}'`
echo $log
ls -l $log*
or run the script as:
Code:
bash-3.00# sh -x ./script.sh
11-23-2008, 08:06 AM
#13
Member
Registered: Jul 2003
Location: London, UK
Distribution: FreeBSD, OpenSuse, Ubuntu, RHEL
Posts: 417
Rep:
What is your shell options set to? Just as an example:
Code:
[jc@home ~]$ test=test
[jc@home ~]$ echo $test*
test.c test.py test.sh test_ssh.sh test.txt test.xml
[jc@home ~]$ shopt -o -s noglob
[jc@home ~]$ echo $test*
test*
11-23-2008, 10:27 AM
#14
Member
Registered: Jul 2005
Location: U.A.E
Distribution: FreeBSD,Fedora,Solaris,AIX
Posts: 168
Original Poster
Rep:
hmmmmm guys, i just went back to home and test the script on my linux machine, its work fine!!!
it seem the issue is from the AIX bash3. strange
i will search and read about bash scripting under AIX.
Thanks guys for your help.
11-26-2008, 10:04 AM
#15
Member
Registered: Nov 2008
Posts: 53
Rep:
Wow ... A Bash shell error held 7 people hostage ...
Don't you just love it when that happens!!!
Linux
Last edited by nehaandrew; 11-30-2008 at 01:17 AM .
All times are GMT -5. The time now is 07:27 AM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News