Web Hosting Talk







View Full Version : Way of using two * in a shell script...


devonblzx
07-12-2007, 01:34 PM
I have bandwidth calculated off of two different machines and I'm trying to consolidate the tally's into one file so I want to change the name on the file then copy it but how do I do this?

My current code looks like:

cat /data/users/*/bandwidth.tally >> /data/users/*/bandwidth.1

Or even if I could do this would be better:

cat /data/users/*/bandwidth.tally >> /data/bandwidth/bandwidth.1.*

The * works as the username in the first part but I see that in the script you cannot have the asterisk in both parts because it doesn't read them as the same.

Anyone know how I would take the username from the * to make it work within the script?

stdunbar
07-12-2007, 01:52 PM
You'll want to modify the script a bit to make a loop. Something on the order of:


#!/bin/sh

for user in /data/users/*
do
name=`basename $user`

cat /data/users/$name/bandwidth.tally >> /data/bandwidth/bandwidth.1.$name
done


I didn't test this but something like this should work.

devonblzx
07-12-2007, 01:57 PM
Thanks for your help, I will definitely give it a shot and let you know if it worked.