Bash scripting: Using wildcard The 2019 Stack Overflow Developer Survey Results Are InHow to...
Have you ever entered Singapore using a different passport or name?
Why do we hear so much about the Trump administration deciding to impose and then remove tariffs?
Is bread bad for ducks?
Is this app Icon Browser Safe/Legit?
Are spiders unable to hurt humans, especially very small spiders?
Can a flute soloist sit?
Time travel alters history but people keep saying nothing's changed
How to answer pointed "are you quitting" questioning when I don't want them to suspect
Where to refill my bottle in India?
Why isn't the circumferential light around the M87 black hole's event horizon symmetric?
Can you compress metal and what would be the consequences?
What is the meaning of Triage in Cybersec world?
Deal with toxic manager when you can't quit
Worn-tile Scrabble
Should I use my personal e-mail address, or my workplace one, when registering to external websites for work purposes?
Button changing it's text & action. Good or terrible?
When should I buy a clipper card after flying to OAK?
Why can Shazam fly?
Why do some words that are not inflected have an umlaut?
Did Section 31 appear in Star Trek: The Next Generation?
Can someone be penalized for an "unlawful" act if no penalty is specified?
If a Druid sees an animal’s corpse, can they Wild Shape into that animal?
How to save as into a customized destination on macOS?
FPGA - DIY Programming
Bash scripting: Using wildcard
The 2019 Stack Overflow Developer Survey Results Are InHow to determine if a bash variable is empty?What is the difference between double and single square brackets in bash?-bash: /usr/bin/ruby: No such file or directoryHow to run a command multiple times, using bash shell?Expect timeout, in Bash scriptingProblem with loading .sh files call out by /usr/bin/phpBash-Scripting - Munin Plugin don't workBash scripting error checking using word count and awkApache upload scanner not working as intendedssh configuration file environment variable?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have two different folders.
The first one contains symlbolic links named with the names of my servers (for example: udcedpai101).
The second one contains the inventory of my servers where the files are named with the server name at the beginning and ending with different paterns. (that's the reason I use the wildcard)
The inventory file name always begins with the name of the servers (for example: udcedpai101-print_manifest.txt
, legpspai101-print_inventaire.txt, legpspai101.myhome.qc.ca-print_inventaire.txt). But they can ending differently.
Here's the command i'm running:
for i in `ls -l /etc/domain.conf | grep ^l | awk {'print $9'}`*; do
ls -l "/var/opt/apache/htdocs/support/print_manifest/$i*";
done
(Partial) output ...
> /usr/local/coreutils/bin/ls: cannot access
> /var/opt/apache/htdocs/support/print_manifest/udcedcgi101*: No such file or directory /usr/local/coreutils/bin/ls: cannot access
> /var/opt/apache/htdocs/support/print_manifest/udcedcgi102*: No such file or directory /usr/local/coreutils/bin/ls: cannot access
> /var/opt/apache/htdocs/support/print_manifest/udcedcgi103*: No such file or directory
I'm trying to use a wildcard (*) in my command but it always returns an error stating that the file isn't there but I can view the file even though the file is there:
ls -l /var/opt/apache/htdocs/support/print_manifest/udcedcgi103*
-rw-r----- 1 TOTO TOTO 69455 Mar 9 00:00 /var/opt/apache/htdocs/support/print_manifest/udcedcgi103-print_manifest.txt
Your assistance would be much appreciated!
bash shell-scripting
bumped to the homepage by Community♦ 13 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I have two different folders.
The first one contains symlbolic links named with the names of my servers (for example: udcedpai101).
The second one contains the inventory of my servers where the files are named with the server name at the beginning and ending with different paterns. (that's the reason I use the wildcard)
The inventory file name always begins with the name of the servers (for example: udcedpai101-print_manifest.txt
, legpspai101-print_inventaire.txt, legpspai101.myhome.qc.ca-print_inventaire.txt). But they can ending differently.
Here's the command i'm running:
for i in `ls -l /etc/domain.conf | grep ^l | awk {'print $9'}`*; do
ls -l "/var/opt/apache/htdocs/support/print_manifest/$i*";
done
(Partial) output ...
> /usr/local/coreutils/bin/ls: cannot access
> /var/opt/apache/htdocs/support/print_manifest/udcedcgi101*: No such file or directory /usr/local/coreutils/bin/ls: cannot access
> /var/opt/apache/htdocs/support/print_manifest/udcedcgi102*: No such file or directory /usr/local/coreutils/bin/ls: cannot access
> /var/opt/apache/htdocs/support/print_manifest/udcedcgi103*: No such file or directory
I'm trying to use a wildcard (*) in my command but it always returns an error stating that the file isn't there but I can view the file even though the file is there:
ls -l /var/opt/apache/htdocs/support/print_manifest/udcedcgi103*
-rw-r----- 1 TOTO TOTO 69455 Mar 9 00:00 /var/opt/apache/htdocs/support/print_manifest/udcedcgi103-print_manifest.txt
Your assistance would be much appreciated!
bash shell-scripting
bumped to the homepage by Community♦ 13 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
2
What's the 9th value you're expecting? can you please display the output ofls -l /etc/domain.conf | grep ^l
? Thanks.
– Itai Ganot
Mar 11 '15 at 16:56
lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi101 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi102 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi103 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi104 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 24 2014 udcedcgi105 -> dev/
– Stoupsi
Mar 11 '15 at 17:05
the can actually end with HOSTNAME-print_manifest.txt, or HOSTNAME-print_inventory.txt. sometime, it could apen the hostname get the FQDN. We do not succeed but thanks for your time. Any idea anybody else?
– Stoupsi
Mar 11 '15 at 18:51
add a comment |
I have two different folders.
The first one contains symlbolic links named with the names of my servers (for example: udcedpai101).
The second one contains the inventory of my servers where the files are named with the server name at the beginning and ending with different paterns. (that's the reason I use the wildcard)
The inventory file name always begins with the name of the servers (for example: udcedpai101-print_manifest.txt
, legpspai101-print_inventaire.txt, legpspai101.myhome.qc.ca-print_inventaire.txt). But they can ending differently.
Here's the command i'm running:
for i in `ls -l /etc/domain.conf | grep ^l | awk {'print $9'}`*; do
ls -l "/var/opt/apache/htdocs/support/print_manifest/$i*";
done
(Partial) output ...
> /usr/local/coreutils/bin/ls: cannot access
> /var/opt/apache/htdocs/support/print_manifest/udcedcgi101*: No such file or directory /usr/local/coreutils/bin/ls: cannot access
> /var/opt/apache/htdocs/support/print_manifest/udcedcgi102*: No such file or directory /usr/local/coreutils/bin/ls: cannot access
> /var/opt/apache/htdocs/support/print_manifest/udcedcgi103*: No such file or directory
I'm trying to use a wildcard (*) in my command but it always returns an error stating that the file isn't there but I can view the file even though the file is there:
ls -l /var/opt/apache/htdocs/support/print_manifest/udcedcgi103*
-rw-r----- 1 TOTO TOTO 69455 Mar 9 00:00 /var/opt/apache/htdocs/support/print_manifest/udcedcgi103-print_manifest.txt
Your assistance would be much appreciated!
bash shell-scripting
I have two different folders.
The first one contains symlbolic links named with the names of my servers (for example: udcedpai101).
The second one contains the inventory of my servers where the files are named with the server name at the beginning and ending with different paterns. (that's the reason I use the wildcard)
The inventory file name always begins with the name of the servers (for example: udcedpai101-print_manifest.txt
, legpspai101-print_inventaire.txt, legpspai101.myhome.qc.ca-print_inventaire.txt). But they can ending differently.
Here's the command i'm running:
for i in `ls -l /etc/domain.conf | grep ^l | awk {'print $9'}`*; do
ls -l "/var/opt/apache/htdocs/support/print_manifest/$i*";
done
(Partial) output ...
> /usr/local/coreutils/bin/ls: cannot access
> /var/opt/apache/htdocs/support/print_manifest/udcedcgi101*: No such file or directory /usr/local/coreutils/bin/ls: cannot access
> /var/opt/apache/htdocs/support/print_manifest/udcedcgi102*: No such file or directory /usr/local/coreutils/bin/ls: cannot access
> /var/opt/apache/htdocs/support/print_manifest/udcedcgi103*: No such file or directory
I'm trying to use a wildcard (*) in my command but it always returns an error stating that the file isn't there but I can view the file even though the file is there:
ls -l /var/opt/apache/htdocs/support/print_manifest/udcedcgi103*
-rw-r----- 1 TOTO TOTO 69455 Mar 9 00:00 /var/opt/apache/htdocs/support/print_manifest/udcedcgi103-print_manifest.txt
Your assistance would be much appreciated!
bash shell-scripting
bash shell-scripting
edited Mar 12 '15 at 9:08
Paul Haldane
3,90211429
3,90211429
asked Mar 11 '15 at 16:42
StoupsiStoupsi
13
13
bumped to the homepage by Community♦ 13 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 13 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
2
What's the 9th value you're expecting? can you please display the output ofls -l /etc/domain.conf | grep ^l
? Thanks.
– Itai Ganot
Mar 11 '15 at 16:56
lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi101 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi102 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi103 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi104 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 24 2014 udcedcgi105 -> dev/
– Stoupsi
Mar 11 '15 at 17:05
the can actually end with HOSTNAME-print_manifest.txt, or HOSTNAME-print_inventory.txt. sometime, it could apen the hostname get the FQDN. We do not succeed but thanks for your time. Any idea anybody else?
– Stoupsi
Mar 11 '15 at 18:51
add a comment |
2
What's the 9th value you're expecting? can you please display the output ofls -l /etc/domain.conf | grep ^l
? Thanks.
– Itai Ganot
Mar 11 '15 at 16:56
lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi101 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi102 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi103 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi104 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 24 2014 udcedcgi105 -> dev/
– Stoupsi
Mar 11 '15 at 17:05
the can actually end with HOSTNAME-print_manifest.txt, or HOSTNAME-print_inventory.txt. sometime, it could apen the hostname get the FQDN. We do not succeed but thanks for your time. Any idea anybody else?
– Stoupsi
Mar 11 '15 at 18:51
2
2
What's the 9th value you're expecting? can you please display the output of
ls -l /etc/domain.conf | grep ^l
? Thanks.– Itai Ganot
Mar 11 '15 at 16:56
What's the 9th value you're expecting? can you please display the output of
ls -l /etc/domain.conf | grep ^l
? Thanks.– Itai Ganot
Mar 11 '15 at 16:56
lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi101 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi102 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi103 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi104 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 24 2014 udcedcgi105 -> dev/
– Stoupsi
Mar 11 '15 at 17:05
lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi101 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi102 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi103 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi104 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 24 2014 udcedcgi105 -> dev/
– Stoupsi
Mar 11 '15 at 17:05
the can actually end with HOSTNAME-print_manifest.txt, or HOSTNAME-print_inventory.txt. sometime, it could apen the hostname get the FQDN. We do not succeed but thanks for your time. Any idea anybody else?
– Stoupsi
Mar 11 '15 at 18:51
the can actually end with HOSTNAME-print_manifest.txt, or HOSTNAME-print_inventory.txt. sometime, it could apen the hostname get the FQDN. We do not succeed but thanks for your time. Any idea anybody else?
– Stoupsi
Mar 11 '15 at 18:51
add a comment |
2 Answers
2
active
oldest
votes
You need to move the second quote in the ls
within the loop to before the *
Change
ls -l "/var/opt/apache/htdocs/support/print_manifest/$i*";
to
ls -l "/var/opt/apache/htdocs/support/print_manifest/$i"*;
You probably don't need the quotes at all. Having the *
inside the double quotes stops it being expanded.
add a comment |
You should not be parsing the output from ls
. Instead, try something like this:
for i in /etc/domain.conf/*; do
test -L "$i" || continue # skip if not a symlink
ls -l "/var/opt/apache/htdocs/support/print_manifest/${i%%*/}"*
done
The second problem is that the asterisk was in double quotes, so the shell was looking for udcedcgi101*
literally, not as a wildcard to expand.
The ${i%%*/}
retrieves just the base name of the file, because the loop now iterates over full path names instead of relative paths within /etc/domain.conf/
.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "2"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f674652%2fbash-scripting-using-wildcard%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to move the second quote in the ls
within the loop to before the *
Change
ls -l "/var/opt/apache/htdocs/support/print_manifest/$i*";
to
ls -l "/var/opt/apache/htdocs/support/print_manifest/$i"*;
You probably don't need the quotes at all. Having the *
inside the double quotes stops it being expanded.
add a comment |
You need to move the second quote in the ls
within the loop to before the *
Change
ls -l "/var/opt/apache/htdocs/support/print_manifest/$i*";
to
ls -l "/var/opt/apache/htdocs/support/print_manifest/$i"*;
You probably don't need the quotes at all. Having the *
inside the double quotes stops it being expanded.
add a comment |
You need to move the second quote in the ls
within the loop to before the *
Change
ls -l "/var/opt/apache/htdocs/support/print_manifest/$i*";
to
ls -l "/var/opt/apache/htdocs/support/print_manifest/$i"*;
You probably don't need the quotes at all. Having the *
inside the double quotes stops it being expanded.
You need to move the second quote in the ls
within the loop to before the *
Change
ls -l "/var/opt/apache/htdocs/support/print_manifest/$i*";
to
ls -l "/var/opt/apache/htdocs/support/print_manifest/$i"*;
You probably don't need the quotes at all. Having the *
inside the double quotes stops it being expanded.
answered Mar 12 '15 at 7:59
Paul HaldanePaul Haldane
3,90211429
3,90211429
add a comment |
add a comment |
You should not be parsing the output from ls
. Instead, try something like this:
for i in /etc/domain.conf/*; do
test -L "$i" || continue # skip if not a symlink
ls -l "/var/opt/apache/htdocs/support/print_manifest/${i%%*/}"*
done
The second problem is that the asterisk was in double quotes, so the shell was looking for udcedcgi101*
literally, not as a wildcard to expand.
The ${i%%*/}
retrieves just the base name of the file, because the loop now iterates over full path names instead of relative paths within /etc/domain.conf/
.
add a comment |
You should not be parsing the output from ls
. Instead, try something like this:
for i in /etc/domain.conf/*; do
test -L "$i" || continue # skip if not a symlink
ls -l "/var/opt/apache/htdocs/support/print_manifest/${i%%*/}"*
done
The second problem is that the asterisk was in double quotes, so the shell was looking for udcedcgi101*
literally, not as a wildcard to expand.
The ${i%%*/}
retrieves just the base name of the file, because the loop now iterates over full path names instead of relative paths within /etc/domain.conf/
.
add a comment |
You should not be parsing the output from ls
. Instead, try something like this:
for i in /etc/domain.conf/*; do
test -L "$i" || continue # skip if not a symlink
ls -l "/var/opt/apache/htdocs/support/print_manifest/${i%%*/}"*
done
The second problem is that the asterisk was in double quotes, so the shell was looking for udcedcgi101*
literally, not as a wildcard to expand.
The ${i%%*/}
retrieves just the base name of the file, because the loop now iterates over full path names instead of relative paths within /etc/domain.conf/
.
You should not be parsing the output from ls
. Instead, try something like this:
for i in /etc/domain.conf/*; do
test -L "$i" || continue # skip if not a symlink
ls -l "/var/opt/apache/htdocs/support/print_manifest/${i%%*/}"*
done
The second problem is that the asterisk was in double quotes, so the shell was looking for udcedcgi101*
literally, not as a wildcard to expand.
The ${i%%*/}
retrieves just the base name of the file, because the loop now iterates over full path names instead of relative paths within /etc/domain.conf/
.
answered Mar 12 '15 at 13:02
tripleeetripleee
80921122
80921122
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f674652%2fbash-scripting-using-wildcard%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
What's the 9th value you're expecting? can you please display the output of
ls -l /etc/domain.conf | grep ^l
? Thanks.– Itai Ganot
Mar 11 '15 at 16:56
lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi101 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi102 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi103 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 25 2014 udcedcgi104 -> dev/ lrwxr-xr-x 1 root sys 3 Jul 24 2014 udcedcgi105 -> dev/
– Stoupsi
Mar 11 '15 at 17:05
the can actually end with HOSTNAME-print_manifest.txt, or HOSTNAME-print_inventory.txt. sometime, it could apen the hostname get the FQDN. We do not succeed but thanks for your time. Any idea anybody else?
– Stoupsi
Mar 11 '15 at 18:51