This is a discussion on script on how to check if the file exists within the Shell scripting forums, part of the Development/Scripting category; Hi all, I am not really familiar with scripting. I just wanna ask a help from anyone on how to ...
|
|||||||
| Register | FAQ | Members List | Calendar | Forgotten your password? | Mark Forums Read |
|
|||
|
Hi all,
I am not really familiar with scripting. I just wanna ask a help from anyone on how to check a file if it exists. I have here my script on how i did it. echo "checking MAKEDEV " if [ ! `ls /dev/MAKEDEV` ]; then exit -1; fi if [ ! `ls /etc/makedev.d/` ]; then exit -1; fi if [ ! `ls /usr/sbin/mksock` ]; then exit -1; fi This is just a simple, if the file exists then it will continue on next, if it does not exists then it will stop. but the problem is if I want to find a lots of file, the tendency is I will type all of this file. Take for example i will check all the files on busybox if it exists, that would be a lot of time typing if and then. My point here is i would like to create loop but i dont know. Maybe i will just type ony: /dev/MAKEDEV /etc/makedev.d /usr/sbin/mksock and then it will loop to find this files, so saving so much time typing. I hope somebody will help. thanks so much, warren |
| Sponsored Links | ||
|
|
|
||||
|
rockdalinux your code seems to correct , but it is only looking for file with -f option for directory you need to add -d option
[code] files="/dev/MAKEDEV /etc/makedev.d /usr/sbin/mksock" # $i will hold single file at a time in following loop for i in $files do if [ ! -f $i -o ! -d $i ]; then exit 1 fi done [code] |
|
|||
|
follow up question....
I have actually posted this for almost a year now. Have patience to review it again. thanks for this script. the script will take the inputs from: files="/dev/MAKEDEV /etc/makedev.d /usr/sbin/mksock" To make my script smaller, I need to create a file which lists all the files that I need to find . Then my script will take the inputs from that file instead of typing it all in the script. How can i do that? Thanks, warren |
|
||||
|
Replace line
Code:
files="/dev/MAKEDEV /etc/makedev.d /usr/sbin/mksock" Code:
INPUTFILE="/tmp/filelist.txt" files="$(cat $INPUTFILE)" |
![]() |
| Bookmarks |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| forced file check fsck | smr36 | Ubuntu / Debian | 3 | 04-16-2008 10:23 AM |
| Shell script to check the disk space on remote systems | vijayscripts | Shell scripting | 5 | 10-21-2007 07:29 PM |
| Command to Check Linux File System | lacloai | Getting started tutorials | 3 | 05-14-2007 06:45 PM |
| shell script to open log files and check for faults | trueman82 | Shell scripting | 1 | 11-23-2006 03:35 AM |
| freebsd ifconfig alias up ioctl siocaifaddr file exists erro | ZigZag | All about FreeBSD/OpenBSD/NetBSD | 1 | 12-23-2005 05:49 PM |