Return to AskMe Archive Main Page
Return to Main PowerUsers.info Main Page
Category : Unix
PowerUsers.info - Paul Doherty Askme Archive of Questions and Answers
----------------------------------------------------------------------
FAQId : 4789806
Subject : How to create a user that has the same UID as another user account?
Question : pauldoherty,
I have a question about unix to trouble you.That is:
How to create a user using "useradd" command that has a UID same to another user
that already exists?
For example ,I have already created a user account "user_one",and its UID is
201.Now I want to create another user account "user_two",and its UID is also
201. I tried "# useradd -d /usr/user_two -u 201 user_two",but I failed.Can you
help me?
Thank you very much.
Answer : Just vi the two following files (as root) and copy and paste the lines
for the user you're attempting to duplicate, then change each occurrence of the
old name in the copied lines to the new user name:
/etc/passwd
/etc/shadow
Afterwards issue:
passwd newuser
where 'newuser' is the name of the duplicate user.
--
Paul Doherty
http://members.home.net/iqueue
Home of DOS/Windows Utilities
Rating :
----------------------------------------------------------------------
FAQId : 5006999
Subject : What i have to do to compress/uncompress a unix directory /test via
gzip or tar
Question : What i have to do to compress/uncompress a unix directory (i.e.
/test) via telnt using gzip or tar ?
Thank you
Answer : If you have a file that looks like this:
file1.tar
it's just tarred and you can extract it like this (assume that file1.tar is in
your /home/user dir):
cd /tmp (or wherever you'd like the file extracted - can be the same dir as the
tar file)
tar -xvf file1.tar
If the file looks like this:
file1.tar.gz
it's been tarred and then compressed with gzip as you mentioned. To get it out
you can do this:
gunzip file1.tar.gz
tar -xvf file1.tar
OR if you have gzcat available you can leave the archive intact and get at the
insides like this:
gzcat file1.tar.gz | tar -xvf -
Also sometimes you may see files like:
file1.tar.Z
This file was tarred and then compressed with "compress" - to get at it:
uncompress file1.tar.Z
tar -xvf file1.tar
Paul Doherty
http://members.home.net/iqueue
Rating :
----------------------------------------------------------------------
FAQId : 5097087
Subject : compress all files and folders in a directory
Question : Hi,
A quick question, how can i compress all files (including other folders) inside
a particular folder?
gzip myfile * -only works on files inside the current folder and does not
include folders
Thank you.
Answer : Try this (assuming you want to archive the /var/stuff directory and all
files/dirs beneath it):
cd /var/stuff
tar -cvpf ..\stuff.tar .
cd ..
gzip stuff.tar
Now you have a file called stuff.tar.gz that contains a compressed version of
all your subdirectory structure including all permissions. To retore it (to the
same or a different system) ensure the /var/stuff dir exists, then:
cd /path/to/archive
gunzip stuff.tar.gz
cd /var/stuff
tar -xvpf /path/to/archive/stuff.tar
And everything is back!
--
Paul Doherty
http://members.home.net/iqueue
Home of DOS/Windows Utilities
Answer : Oops - realized I have a backslash instead of a forward slash in the
tar command - change that from
tar -cvpf ..\stuff.tar .
to
tar -cvpf ../stuff.tar .
After the first two commands:
cd /var/stuff
tar -cvpf ../stuff.tar .
you will have created a 'stuff.tar' file in the directory above the one you're
in. (You can also tar to any other directory you like by using it in place of
"../" like /tmp/stuff.tar) That's where the next command:
cd ..
comes in - it moves you up one directory to where the file exists. then you
compress that file with:
gzip stuff.tar
and gzip compresses the file into stuff.tar.gz and deletes the original .tar
file.
--
Paul Doherty
http://members.home.net/iqueue
DOS/Windows Utilities
Rating :
FUQuestion : The first command worked fine, but now i can't find the .tar file.
any ideas?
----------------------------------------------------------------------
FAQId : 5172809
Subject : installing solaris 8
Question : Hi,
I am trying to install solaris 8 on a sun microsystem ultra 10 elite 3D with two
hard drives. It lets me enter all the info and then tells me that the name
server is wrong it seems like its a hard drive problem.
heres the partition layout
o. c0t0d0 <seagate medalist 34342a cyl 8892 alt 2hd 15 sec 63> /pci@1f,0/pci@1,1/ide@3/dad@0,0
1. c0t1d0 <ST34342A cyl 8892 alt 2hd 15 sec 63> pci@1f, 0/pci@1/ide@3/dad@1,0
heres the full map
part tag flag cylinders size blocks
0 unassigned wm 0 0 (0/0/0) 0
1 swap wu 0-1109 512.18Mb (1110/0/0) 1048950
2 backup wm 0-8891 4.01GB (8892/0/0) 8402940
3 unassigned wm 0 0 (0/0/0) 0
4 " " " " " "
5 " " " " " "
6 " " " " " "
7 " " " " " "
I'm not sure how to prepare the disk if it isn't prepared properly.
can you advise?
thanks
Pat
Answer : Well it's a bit more than that. You'll need to find the line in
nsswitch.conf that looks like this:
hosts: files nis
and make it like this:
hosts: files dns nis
(and remove nis altogether if you like)
In resolv.conf you'll need this:
domain wherever.com
nameserver 214.24.38.32
nameserver 214.24.38.33
search wherever.com
In the above info you'll use your own DNS domain and name server addresses.
/etc/defaultdomain is just a text file with the domain name (same as in the file
above) in it.
/etc/hosts will contain information about any hosts (including your own machine)
that you need to know about even if DNS fails.
For example:
#
# Internet host table
#
127.0.0.1 localhost
10.1.1.9 elfstone elfstone.wherever.com loghost
"elfstone" is the local machine I am configuring.
Finally you will need a file called:
/etc/nodename.xxx
where 'xxx' is the device name for your interface card. You can find it by
typing:
ifconfig -a
"lo0" is the loopback device and can be ignored. We're after the other one -
like hme0, or le0. Once you determine which it is make the file as above and put
the hostname of your machine in it on a line by itself.
Reboot after this and you should be in business.
--
Paul Doherty
http://members.home.net/iqueue
Home of DOS/Windows Utilities
Answer : That is a known bug with Solaris 8's install. It will never succeed at
this point in the install if you select DNS. Just start a new install and select
"no name service" when asked. After the install add the DNS info you need in the
form of:
/etc/nsswitch.conf
/etc/resolv.conf
/etc/defaultdomain
/etc/hosts
--
Paul Doherty
http://members.home.net/iqueue
DOS/Windows Utilities
Rating :
FUQuestion : Hi,
thanks for the info do i just edit these files and put in my ip addresses? And
finally
what book should i get if i want to be a solaris expert?
many many thanks
pat
----------------------------------------------------------------------
FAQId : 5274304
Subject : Changing IP on hme1
Question : Hi, Paul!
I inherited a Sun220R to admin. IPv4 on Solaris8. It has 2
ethernet interfaces set to local 'reserved network' static IP numbers. I'm being
asked to put this machine on the outside of the firewall temporarily for
testing. I can plug it into a hub for this purpose. I have an external IP
number, netmask (not in hex though), and gateway router to point to for the hme1
interface.
'ifconfig -a' shows me the IP, netmask etc. I can 'ifconfig hme0 down' to take
down temporarily the primary interface.
How do I change the address of the hme1 interface? What commands must be invoked
to change the address so that I can then unplug it from the internal switch and
plug it into the external hub? Do I have to reboot the 220R for this to change?
Can't seem to find a straight answer on Sun's BigAdmin.
Ultimately, I'd like to make this machine a multihomed host - hme0 live to the
inside and hme1 live to the outside. There should be no packet forwarding
between interfaces and I don't want this to be a router, but then this machine
would be available for testing by engineers.
If you can help, thanks!
(please cc reply to kenzo562@iname.com if possible...)
Answer : Yes, just add extra lines for the backup default routes to
defaultrouter and you're set.
As for packet-forwarding. Yes I'd lock that machine down if it's going to stay
exposed to the internet at large. Unless this machine will be a firewall (in
which case it pretty much needs to route :-) I'd leave routing disabled - and if
someone does hack into it you're still at risk since they can potentially change
the configuration and get into the internal network if you have it plugged into
an ethernet cable.
--
Paul Doherty
http://members.home.net/iqueue
Home of DOS/Windows Utilities
Answer : Yes just add lines as needed to /etc/netmasks for each network
interface. Follow the same format as the line you quoted. Your new line would
then be (if that was indeed your network and subnet mask):
63.81.163.0 255.255.255.240
Any access to a 63.81.163.0 address, or any interface that talks on a network
listed in netmasks, will be assumed to use that netmask unless overridden by an
ifconfig statement later.
I don't think you will want to be running route statements after disabling the
routed daemon and touching the /etc/notrouter file. Just create a single line
text file /etc/defaultrouter that has the IP of the interface you want to go to
as your default. So for instance it might be:
63.81.163.1
--
Paul Doherty
http://members.home.net/iqueue
Home of DOS/Windows Utilities
Answer : You won't need a reboot - you just need some more ifconfig commands. To
change the IP of an interface do it like this:
ifconfig hme1 123.12.13.14 netmask 255.255.255.240 up
Make sure your default router (gateway/router port) is defined on a single line
in /etc/defaultrouter and that your netmasks are defined in /etc/netmasks.
To stop the machine from routing you only need to do this:
touch /etc/notrouter
and reboot.
To be really sure it doesn't get turned on disable the routed daemon in /etc/inet/services.
--
Paul Doherty
http://members.home.net/iqueue
Home of DOS/Windows Utilities
Rating :
Rating :
FUQuestion : Thanks Paul!
Turns out that the ethernet interface on the motherboard is multihomed with two
internal addresses.
I shut down both, detached the wire from the internal switch and attached it to
the external hub, assigned hme1 the external address and it was pingable from
the outside. I did not change the defaultrouter content which is an internal
address but it still worked. Can defaultrouter have two lines with unique
addresses?
In the future, I'd like to remain connected externally and use the second
physical interface connected internally but I don't want the fat pipe from the
external thru the CPU to the internal. Will turning off packet forwarding
accomplish this or is it just too dangerous once the CPU is penetrated?
FUQuestion : Thanks for your quick response!
In /etc/netmasks, I have the original
<subnet> <netmask> in place:
172.16.0.0 255.255.255.0
Do I add the lines of the outside network right under the lines of the internal
network as part ofthe process of moving the machine outside of the private
network? That would be:
63.81.163.xxx 255.255.255.240
About /etc/defaultrouter: Is running:
# /usr/sbin/route add default 63.81.163.yyy 1
....the way to add a line in /etc/defaultrouter?
Thanks!
----------------------------------------------------------------------
FAQId : 5509521
Subject : mail
Question : On Solaris, I entered this command "mail cindy@localhome.com <
"filename"
It works ok. Now, I would like to enter a subject when mailing this file, but
cannot figure out how.
Thank you, Cindy
Answer : mailx -s "Check this out!" email@home.com < /wherever/filename
Paul Doherty, CNE, MCP+I, MCSE, CCSA, CCSE
http://members.home.net/iqueue
Home of DOS/Windows Free Utilities
Rating :
----------------------------------------------------------------------
FAQId : 5685813
Subject : how do I write a korn script to ftp files from one server to another
Question : how do I write a korn script to ftp files from one server to another
Answer : Here is an example of a ksh script to do just that:
#!/usr/bin/ksh
# for auto FTP to work you will need a chmod 600 file in the originating user's
dir
# with the following line (.netrc file):
# machine mymachine.wherever.com login myusername password mypassword
ftp mymachine.wherever.com 1>/dev/null <<!EOF
bin
lcd /var/log/
cd log
put myfile.tar.gz
bye
!EOF
--
Paul Doherty
http://members.home.net/iqueue
DOS/Windows Utilities
Rating :
Rating :
----------------------------------------------------------------------
FAQId : 6435337
Subject : Unix statement
Question : Pls advise the correct interpreatations of the following Unix
statement:
rm -rf ` ls /tmp | sed -e `/^\.$/d -e /^\.\.$/d'`
Answer : It is a garbled sed statement as-is, but it appears to be trying to
remove all files from the /tmp directory *except* the "." and ".." directory
entries. Here is what it should look like:
rm -rf `ls /tmp | sed -e '/^\.$/d' -e '/^\.\.$/d'`
The first part of the sed statement:
-e '/^\.$/d'
will look for lines that begin(^) with a period (\.) and are followed by nothing
up to the end of the line($). It will then delete(/d) those lines.
The second part of the sed statement:
-e '/^\.\.$/d'
performs a second edit command and does the same as the first, except it looks
for two periods and and end-of-line (EOL).
--
Paul Doherty
http://members.home.net/iqueue
DOS/Windows Utilities
Rating :
----------------------------------------------------------------------
FAQId : 6996130
Subject : Copy files from unix
Question : Hi from italy.
I'm not very skilled in UNIX.
Can i copy with the command cp all the file with a creation date greater of a
specified date?
Thanks for all.
Gian Paolo from Milan.
Answer : Don't forget to rate the answers you receive on AskMe.com... thanks!
Answer : To do this you will need a file that has a date of creation/access the
same as the cutoff date and time you want to use. To create a fil just issue a
command like this:
touch -t 12021630 /tmp/stuff
This will create a file "/tmp/stuff" that will show a creation/access date of
Dec 02 of the current year (several days ago). You then can use that file to
perform the search and copy for files newer than that with this:
cd /wherever/your/files/are
find . -newer /tmp/stuff -type f -exec cp {} /wherever \;
"-newer /tmp/stuff" indicates you only want files newer than the date of the
file you just created.
The "-type f" will ensure that only files are copied and not directories.
The "-exec cp {} /wherever" will copy each found item to /wherever.
--
Paul Doherty
http://home.attbi.com/~bitbucket911
DOS/Windows Utilities
----------------------------------------------------------------------
FAQId : 7562947
Subject : repalce
Question : hi, how can you replace certain words that sit
across multiple files ?
if you can't, i think you can create a batch file that does the replace function
to files that is specified in the batch.
I have tried to make one, it is not like DOS and can't even run the script.
Can you please show me how to do these?
Thanks in advance
Best regards
Tomo
Answer : How about something like this, where the word I'm searching for is
'stuff' and I want it replaced with 'mystuff' in all the files:
#!/usr/bin/ksh
for i in $*
do
cat $i | sed -e 's/stuff/mystuff/g' > /tmp/xyz
cat /tmp/xyz > $i
done
For testing I invoked it as follows:
./replace.ksh file1 file2 file3
The files contained the following:
file1:
This is an example of stuff that should be replaced.
file2:
Another example of
stuff
I want replaced.
This stuff has got to stop!
file3:
YASINR - Yet Another Stuff I Need Replaced - is this stuff getting boring yet?
When done all the files have the term 'stuff' replace with 'mystuff'.
--
Paul Doherty
http://home.attbi.com/~bitbucket911
DOS/Windows Utilities
Rating :
----------------------------------------------------------------------
FAQId : 7672604
Subject : Setting CHRONTAB to mail me my 'Sent-Messages'
Question : Hi there,
Is it possible to set up a chrontab operation in my account so as to send me
mail that is located in my "~/folder/sent-messages" file (~ being my home
directory)? I am very new to UNIX so i have no idea how to do this. My shell is
"tcsh". I believe when i log out i guess the chrontab feature will be lost or
will it? I would like this chrontab to send me these messages every 1 week if
possible.
Because the "sent-messages" file can be really big after time can someone also
tell me how to just send the last 4 sent messages located in this file? I can
use the "tail" command but it would be nice to no exactly where the 4 last
messages are so it can chrontab to send those only.
Tbanks very much
Answer : I already answered this one privately, but since it's here too I'll
duplicate the answer here:
You can create a crontab with:
crontab -e
You may need to set EDITOR and/or VISUAL environment variables prior to running
the command - I'd set both like this:
EDITOR=/usr/bin/vi
VISUAL=/usr/bin/vi
export EDITOR
export VISUAL
Once inside the file add a line at the bottom like this:
* * * * 6 /usr/local/scripts/sendmemymail
Save it with <ESC>, followed by :wq
As for the sendmemymail command make sure it starts with:
#!/usr/bin/ksh
as the first line. Then to send the mail in the script use:
cat ~/folder/sent-messages | mail myemail@myisp.com
I don't know the format of your emails so I can't really suggest a way for you
to prune out the last 4 exactly, but you can always use tail with a parameter to
grab the last 100 lines or so:
cat ~/folder/sent-messages | tail -100 | mail myemail@myisp.com
--
Paul Doherty
http://home.attbi.com/~bitbucket911
DOS/Windows Utilities
Answer : I fixed it for you:
#!/usr/bin/ksh
tail -r /wherever/home/myhomedir/sent-mail > /tmp/reversed
cat /tmp/reversed | awk 'BEGIN { count = 0 }
/^From:/ { count++ }
{ if (count < 4) print
else {
print
exit
}
}' > /tmp/chopped
echo "LAST 4 MESSAGES" >> /tmp/chopped
tail -r /tmp/chopped | mail myemail@myisp.com
--
Paul Doherty
http://home.attbi.com/~bitbucket911
DOS/Windows Utilities
Rating :
Rating :
FUQuestion : Hi Paul,
I got this code from CHL (another expert) but i cant seem to be able to get it
working. It is able to send me the last 4 msgs in the "sent-mail" file.
Unfortuantely, I always get the same error msg:
awk: syntax error near line 7
awk: illegal statement near line 7
awk: bailing out near line 8
No message !?!
Here is my script file:
-------------------------
#!/usr/bin/ksh
tail -r folder/sent-mail > re
cat re | awk '
BEGIN {
count=0
}
/^From/ { count = count + 1 }
{ if ( count < 4 )
then { print }
else { print;
exit
}
}' > chopped
tail -r chopped | mail howdy@woof.com
------------------
Any clues?
And is it possible to turn off crontab from sending me email msgs if errors
occur in the crontab task?
----------------------------------------------------------------------
FAQId : 8084218
Subject : copy files
Question : Hi there
I am making a script that will copy files from one Solaris box to another. I
know the list of files I want, so how do I initiate a script that effectively is
an automated FTP copy from one box to another?
Answer : Here's a nice way to do it:
http://www.columbia.edu/kermit/ftpscript.html
Another easier way is to create a file named .netrc in your home directory, then
chmod it:
chmod 600 .netrc
Inside the .netrc put this line:
machine othermachine.mydomain.com login <username> password <password>
Now that this file is in place (and protected from view) you can put something
similar to the following into another script file to automate FTP sessions to
'othermachine':
ftp othermachine.mydomain.com 1>/dev/null <<!EOF
bin
prompt
lcd /var/tmp
cd backup
mput *.gz
bye
!EOF
In the example above I connect to the remote machine, change the transfer type
to binary (bin), change my local dir to /var/tmp, change the remote directory to
./backup, and then do a multi-put of all *.gz files from /var/tmp to the remote
machine's ./backup directory.
--
Paul Doherty
http://home.attbi.com/~bitbucket911
DOS/Windows Utilities
Rating :
----------------------------------------------------------------------
FAQId : 8084373
Subject : finding files
Question : Hi there
How do you find file names only through the entire directory?
I do not want to find text in files. Just a file name in the directory.
thanks
Answer : Say you are wanting to search /usr (whole branch including
subdirectories) for a filename of 'myfile' (you can also use wildcards here):
cd /usr
find . | egrep myfile
--
Paul Doherty
http://home.attbi.com/~bitbucket911
DOS/Windows Utilities
Rating : PowerUsers.info - Paul Doherty Askme Archive of Questions and Answers