Sponsored Content
Full Discussion: rm error codes and logging
Top Forums Shell Programming and Scripting rm error codes and logging Post 302606106 by hateborne on Friday 9th of March 2012 02:34:45 PM
Old 03-09-2012
rm error codes and logging

Afternoon ladies and gents,

I am trying to create a simple script to remove a certain file from a user's network profile location. The removal works ok, but in the interest of overkill I would like to add a simple error detection (such as file doesn't exist or permission denied)

Currently, it works perfect assuming nothing is missing and I have permissions to run it. It outputs all the removed files to the log. If permission denied or file does not exist, it skips the append ending and dumps it into terminal. Is there any way I may be able to log the errors as well?

Part in question:
Code:
array=( $( ls -1p | grep / | sed 's/^\(.*\)/\1/') )
for (( i=0; i<${#array[*]}; i++));
    do
        rm -v /profiles/${array[i]}path/to/file.extension >> ~/Desktop/MyLog.log
    done

Note: The $array variable returns "FolderName/" instead of just "FolderName". This explains it being "/profiles/${array[i]}path/to/file.extension" instead of "/profiles/${array[i]}/path/to/file.extension".

I understand it may involve a small "if-then" statement, I am just clueless go about it.

Thank You!

-Hate

---------- Post updated at 02:34 PM ---------- Previous update was at 02:25 PM ----------

Dave_L on Ubuntu Forums solved this (very quickly I might add).

Code:
rm -v /profiles/${array[i]}path/to/file.extension >> ~/Desktop/MyLog.log 2>&1

Adding "2>&1" after MyLog.log was the fix.

Thanks!

-Hate
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

GNU's make error codes - list

Hi, I often encounter make errors. Many a times, a corresponding error code is also shown, like make: Error 56 (ignored) make: Error 91 (ignored) make: Error 96 (ignored) et al. I tried google'ing as well as searching this forum for what these error codes mean. I know, make... (1 Reply)
Discussion started by: vino
1 Replies

2. AIX

pSeries 610 error codes

I have been given some pSeries AIX servers to maintain. One of the servers wont come up after a shutdown and the following code is showing on the server: 10118401 How do I look up the error code? (2 Replies)
Discussion started by: dangral
2 Replies

3. UNIX and Linux Applications

Printing unix error codes

Hi Friends, I need your help in understanding this: :rolleyes: I want to print the error numbers returned by the system calls (not the actual integers but the strings that they match to). The error numbers like EACCESS, ENOMEM, ENOENT etc ... For eg: returnCode = open(somefile,... (2 Replies)
Discussion started by: vijaya2006
2 Replies

4. Shell Programming and Scripting

ssh use of error codes

I want to import the info to shell when the connection to remote host was closed . I have follwed by ssh errors but how to use variables in script. I am thinking out loud the shell script could look as follow: svnvaraible=$ERROR_SSH_CONNECTION_LOST if ; then break fi (1 Reply)
Discussion started by: Michal Janusz
1 Replies

5. Solaris

Sun T2000 error codes

I got a Power supply failure. I replaced the power supply and still got the error. Any ideas on what I should try next? (1 Reply)
Discussion started by: 642fiddi
1 Replies

6. UNIX for Advanced & Expert Users

Error Codes for VCS

Do we have common VCS error codes for all platforms. eg. 10195 Agent(s) for group %s failed on system %s for all Linux,Solaris and windows ? (1 Reply)
Discussion started by: NIMISH AGARWAL
1 Replies

7. Shell Programming and Scripting

Capturing Oracle SQL Error Codes

My issue pertains to earlier posts like exit unix script after sqlerror in procedure - dBforums SQLPLUS Error Capturing | Unix Linux Forums | Shell Programming and Scripting We are executing PL/SQL blocks from shell scripts using SQLPLUS. The error code has to be captured into a logfile that... (3 Replies)
Discussion started by: jerome_rajan
3 Replies

8. Shell Programming and Scripting

FTP exit and error codes

I have a script which connects to a remote server via FTP and gets some file from there. #!/bin/bash /usr/bin/ftp -n remote.hostname.com <<EOF quote USER user123 quote PASS password123 lcd /dir1/dir2/dir3 cd / mget file_pattern* close bye EOF rc=$? if ] ... (7 Replies)
Discussion started by: dhruuv369
7 Replies

9. Shell Programming and Scripting

BASH - Propagation of error codes

Hello. I use bash functions which are in different script files. Theses scripts function files are sourced when necessary. As function does not easily return string value, Value are return using the echo function, and a return code is returned.. Now here my question : In the main script I... (11 Replies)
Discussion started by: jcdole
11 Replies

10. Shell Programming and Scripting

Capturing error codes in SFTP commands

Hi, I have been using the SFTP commands in my reusable shell scripts to perform Get/Put operation. The script has a list of 6 errors which i am capturing through the log file using grep command. But I feel there might me more errors which the script might need to capture. I tried to capture the... (2 Replies)
Discussion started by: Bobby_2000
2 Replies
GENPROF(8)							     AppArmor								GENPROF(8)

NAME
aa-genprof - profile generation utility for AppArmor SYNOPSIS
aa-genprof <executable> [-d /path/to/profiles] OPTIONS
-d --dir /path/to/profiles Specifies where to look for the AppArmor security profile set. Defaults to /etc/apparmor.d. DESCRIPTION
When running aa-genprof, you must specify a program to profile. If the specified program is not a fully-qualified path, aa-genprof will search $PATH in order to find the program. If a profile does not exist for the program, aa-genprof will create one using aa-autodep(1). Genprof will then: - set the profile to complain mode - write a mark to the system log - instruct the user to start the application to be profiled in another window and exercise its functionality It then presents the user with two options, (S)can system log for entries to add to profile and (F)inish. If the user selects (S)can or hits return, aa-genprof will parse the complain mode logs and iterate through generated violations using logprof(1). After the user finishes selecting profile entries based on violations that were detected during the program execution, aa-genprof will reload the updated profiles in complain mode and again prompt the user for (S)can and (D)one. This cycle can then be repeated as neccesary until all application functionality has been exercised without generating access violations. When the user eventually hits (F)inish, aa-genprof will set the main profile, and any other profiles that were generated, into enforce mode and exit. BUGS
None. Please report any you find to bugzilla at <http://bugzilla.novell.com>. SEE ALSO
apparmor(7), apparmor.d(5), aa-enforce(1), aa-complain(1), change_hat(2), aa-logprof(1), logprof.conf(5), and <http://forge.novell.com/modules/xfmod/project/?apparmor>. NOVELL
/SUSE 2008-06-11 GENPROF(8)
All times are GMT -4. The time now is 09:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy