- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shell Script required
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2010 09:07 PM
04-25-2010 09:07 PM
Anybody can assist me. How we can write a shell script. I don't basic of that and i need a script.1.List all the file along with their permissions in the server.
Thanks for your prompt action.
Regards,
Dev
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2010 09:13 PM
04-25-2010 09:13 PM
Re: Shell Script required
Why you need a script for that ??
go to /
#pwd
/
#ls -lR > /list
regards,
Sooraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2010 09:35 AM
04-26-2010 09:35 AM
SolutionYou could reduce (filter) the recursive output of 'ls -lR' to do:
# ls -lR /root|awk '{if (NF>3) {print $1,$NF} else {print}}'
...which might yield:
/root/.cpan:
total 26160
-rw-r--r-- FTPstats.yml
-rw-r--r-- Metadata
-rw-r--r-- histfile
drwxr-xr-x sources
/root/.cpan/sources:
total 16
drwxr-xr-x authors
drwxr-xr-x modules
/root/.cpan/sources/authors:
total 336
-rw-r--r-- 01mailrc.txt.gz
/root/.cpan/sources/modules:
total 2064
-rw-r--r-- 02packages.details.txt.gz
-rw-r--r-- 03modlist.data.gz
Redirect the output to a file as you see fit:
# ls -lR /path|awk '{if (NF>3) {print $1,$NF} else {print}}' > myls.out
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2010 11:24 AM
04-26-2010 11:24 AM
Re: Shell Script required
> ...which might yield:
> [...]
It might, if all your users cooperate, and
don't create any files with funny names.
dyi # ls -lR fun
total 48
-rw-r--r-- 1 root sys 6 Apr 26 14:13 a b c
-rw-r--r-- 1 root sys 6 Apr 26 14:13 d e f
-rw-r--r-- 1 root sys 2 Apr 26 14:15 x
dyi # ls -lR fun | awk '{if (NF>3) {print $1,$NF} else {print}}'
total 48
-rw-r--r-- c
-rw-r--r-- f
-rw-r--r-- x
Everything's complicated, I always say.
"find" tends to have a good idea of
what/where a file name really is. The output
format of "ls -l" is such a mess that trying
to parse it (in any elementary way) is asking
for trouble. (And sometimes you'll get what
you ask for.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2010 11:38 AM
04-26-2010 11:38 AM
Re: Shell Script required
Why Dev, do you need a full listing?
Did anyone do a chown -R from / directory?
Let us know - then we can think of the best fitting solution.
SNS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2010 12:29 PM
04-26-2010 12:29 PM
Re: Shell Script required
> Steven: It might, if all your users cooperate, and don't create any files with funny names.
You are correct of course. I was offering a simplistic solution under the conditions that "reasonable" file naming had been followed. Yes, we both know that many users (intentionally or otherwise) are not reasonable or knowledgeable of corner cases.
If I wanted more rigor, I'd do:
# perl -MFile::Find -we 'find(sub{printf "%04o %-s\n",(stat(_))[2]&07777,$File::Find::name if -f $_},".")'
...or, if I'm running Linux:
# find . -type f -printf "%04m %h/%f\n"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2010 01:43 PM
04-26-2010 01:43 PM
Re: Shell Script required
# find / -type f -exec ls -l {} \; |awk '{for (i=2;i<9;i++){$i=""};print $0}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2010 09:37 PM
04-26-2010 09:37 PM
Re: Shell Script required
Thanks to all of you for provinding Valuable infomation.
As somebody ask why you need this script
>> As Business requirement. Scripting is manadatory thing, so i want learn also.
Could you please assist me or can you share some document regarding shell scripting I want learn and create some scripting(HP-UX).
I would be thankfull to all if you will be provide some document regarding same.
Regards,
Dev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2010 10:37 PM
04-26-2010 10:37 PM
Re: Shell Script required
# ls -LR >/list gives only the listing of file. As i mention in questions I need all files with permission.
Regards,
Dev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2010 10:45 PM
04-26-2010 10:45 PM
Re: Shell Script required
Listening is also important like reading!!!
I have mentioned -lR ( lowercase l-el and capital R)...
Unix is a case sensitive OS! different switches -small mistakes - bigger differences !!!
:)
Regards,
Sooraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2010 11:42 PM
04-26-2010 11:42 PM
Re: Shell Script required
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2010 01:49 AM
04-27-2010 01:49 AM
Re: Shell Script required
# ls -lR > /list
#
I got O/P only when i have given ls -lR
but its O/P is too big.
Thanks & Regards,
Dev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2010 01:59 AM
04-27-2010 01:59 AM
Re: Shell Script required
What do you want instead?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2010 04:10 AM
04-27-2010 04:10 AM
Re: Shell Script required
As i am learning scripting and expect that after creating scripting o/p will comes as below requirement.
1.List of the files with permissions 755.
2. List all the files created or modified 2 days back.
3.List all the files owned by certain user
Thanks for assisting me.
Regards,
Dev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2010 04:26 AM
04-27-2010 04:26 AM
Re: Shell Script required
> 1.List of the files with permissions 755.
# find /path -type f -perm 755
> 2. List all the files created or modified 2 days back.
# find /path -type f -mtime +1
...which yields files older than 48-hours.
> 3.List all the files owned by certain user
# find /patch -type f -user dev
See the manpages for 'find()'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2010 04:40 AM
04-27-2010 04:40 AM
Re: Shell Script required
Thanks a lot for your quick response.
Now i can see the O/P but if you have script for that than really its worthfull for me because i am learning scripting.
Scripting is always better than command.
Hope you will share scripting of that if you have.
Reagrds,
Dev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2010 05:28 AM
04-27-2010 05:28 AM
Re: Shell Script required
Scripting doesn't always need to be:
sh scriptname.sh
JRF's "commands" you have seen, are very much the basis of the complex scripts that are to be written later.
Now, the question here is - did those tools made it easier that the normals commands ls ....Well, you got the answer :-)
This is the start, the base.
Hard works pays off, eventually - Happy Learning!
HTH
SNS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2010 05:51 AM
04-27-2010 05:51 AM
Re: Shell Script required
Hope all above solutions answers your question.
However to learn shell scripting you have to spend some time dedicatedly:
- get the book/documentation.
- get the system and unix command prmpt ready.
- read theory.
- write small script and practice.
- for any doubt question 1. google it or , ask for help in the forum with examples.
- If you are very new , it is suggested to spend 4 to 8 weeks learning the prgramming and flow control, looping , condition , string operation ,regular expressions etc. And you will be good soon..
Finally check out few documents here:
#--------------------------------------
1. Unix Shell scripting Tutorial:
http://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/unixscripting/unixscripting.html
2. The Bourne Shell:
http://www.grymoire.com/Unix/Sh.html
3. Linux Shell Scripting Tutorial v1.05r3 ( A Beginner's handbook ):
http://www.freeos.com/guides/lsst/
#-----------------------------------------
Good Luck and Cheers,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2010 06:03 AM
04-27-2010 06:03 AM
Re: Shell Script required
Also check this out:
UNIX shell scripting with ksh/bash::
####################################
The goals of this class are to enable you to:
Learn what kinds of problems are suited to shell scripts
Review the most commonly used Unix commands that are useful in shell scripts.
Write simple shell scripts using the Bourne, Korn or Bash shells
-------------------
very good ,and with examples:
Started with basic script like:
1: #!/bin/sh
2: date
3: pwd
4: du -k
################################
Link:
http://www.dartmouth.edu/~rc/classes/ksh/print_pages.shtml
Good Luck,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2010 08:35 AM
04-27-2010 08:35 AM
Re: Shell Script required
===> Scripting is always better than command.
I wonder how you can have script with out command!!!!!
To meet your requirement to find out all those specific files , only one single line command is required.
Regards,
Sooraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2010 08:13 PM
04-27-2010 08:13 PM
Re: Shell Script required
Thanks a lot for guiding me to learn shell scripting. I will follow the same way as you mention in forum.
Soorj- 'Scripting is set of command ' In limited time you will find many o/P with the help of scripting in that way i was mention scripting is better than command.
Regards,
Dev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2010 02:02 AM
04-28-2010 02:02 AM
Re: Shell Script required
>>Now i can see the O/P but if you have script for that than really its worthfull for me because i am learning scripting.
>>Scripting is always better than command.
>>Hope you will share scripting of that if you have.
Just copy/paste into a file this 3 lines, save the file and execute at the prompt
vi myscript
find /path -type f -perm 755
find /path -type f -mtime +1
find /patch -type f -user dev
save the file
execute the file
$sh ./myscript
set of commands kept into a file and execute thats called scripting.
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2010 02:17 AM
04-28-2010 02:17 AM
Re: Shell Script required
Hope that we have been able to help you out!
Let Us know your progress when U get stuck
Seems like Cleris & Dev are pals
- lot of "quoted" interactions amongst them
Please close the thread if you are satisfied..
Danke/Merci
SNS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2010 08:25 PM
04-28-2010 08:25 PM
Re: Shell Script required
Thanks to all.
I got Satisfactory answer.
Regards,
Dev