[HW] Script so that when i execute the "rm" command


 
Thread Tools Search this Thread
Operating Systems Solaris [HW] Script so that when i execute the "rm" command
# 1  
Old 10-18-2012
Question [HW] Script so that when i execute the "rm" command

Hi guys,

I need to write a script so that when i execute the "rm" command, the file mentioned need to be copied to other folder and then be deleted. this should be done in back ground. can you please help me out??


I have written a code in c for this but i dont have C compiler and i dont have admin rights to install too.

Code:
 #include<stdio.h>
  #include<unistd.h>
  #include<fcntl.h>
  #include<sys/types.h>
  #include<string.h>
  
  int main(int argc, char *argv[])
  
  {
              if(argc <= 1)
              {
                          printf("specify the file to be removed\n");
                          printf("exiting\n");
                          exit(0);
              }
              execlp("cp","cp",argv[1],/usb_hdd1/deleted_files,NULL);
              execlp("rm"."rm",argv[1],NULL);
              return 0;
  }           



The above is the code i have written. can i have something like this in shell??

Moderator's Comments:
Mod Comment Closed: Homework Infraction
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Shell Programming and Scripting

"Cannot Execute" script, SunOS. [solved]

I have a script in Server A that will run a script in ServerB. #!/bin/ksh/ ssh user@server "/path/script.sh" The script permissions are as follow: -rwxrwxrwx 1 user dba 75 Jun 11 10:00 script.sh I checked the existence of 'ksh' in /bin and its there. (bash isnt) ... (0 Replies)
Discussion started by: RedSpyder
0 Replies

4. UNIX for Dummies Questions & Answers

Unix "look" Command "File too large" Error Message

I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this: $ look "string" "/home/patrick/filename.txt" However, this gives me the following message: "look: /home/patrick/filename.txt: File too large" So, I have two... (14 Replies)
Discussion started by: shishong
14 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

7. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

8. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

9. Shell Programming and Scripting

Difficulty using "execute immediate" in shell - Sql script

Hello members, I get an unexpected "end of file" error while trying to execute the following piece of code in the bash / ksh shell. I'm assuming the problem is with using the "execute immediate statement" #! /bin/bash tname="table" for i in * do sqlstr="create table $tname$i as select... (3 Replies)
Discussion started by: novice82
3 Replies

10. Shell Programming and Scripting

how do execute "vi" commands in shell script?

Hi All, I need to execute the following "vi" commands in my script. How can I do that?? pls help me.... 1. escape (escape mode) 2. gg (goto first line) 3. shift+v (visual mode) 4. shift+g (goto to last line) 5. = (alinment) Thanks in advance, Saravana (3 Replies)
Discussion started by: askumarece
3 Replies
Login or Register to Ask a Question