Retrieving File's Mime-type


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Retrieving File's Mime-type
# 1  
Old 01-02-2009
Retrieving File's Mime-type

Alright, so I am trying to use perl (or any other shell scripting language, awk/sed/bash for instance), to retrieve the mime-type of a file.

I want to keep it in one file, and most of the modules that are on cpan that check for mime types (Magic), aren't installed on these boxes.

Anyone have a good way of checking for a file's mime type?
# 2  
Old 01-02-2009
If you have the .pm file for mime type checking (for example like Lite.pm for mime::lite)
you do not necessarily have to "install" the module. Just put it in your directory on the machine you are using, say /home/Rhije/Lite.pm

and add this to the shebang in the top of your own perl code
Code:
#!/bin/perl -I/home/Rhije/Lite.pm

This may not always work, but mime content-type checking is reasonably complex, so it is definitely worth a try. Rather than rolling your own. You can pack the two files in a tarball, extract them and run the perl. I know it violates your "one file" request.
# 3  
Old 01-02-2009
Sorry, not sure if I called it the correct thing. I meant the content type, such as image/*

I am trying to find what type of file it is, image, video, script, etc..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

MIME type for sending gzip file as attachment in email

Hello, I am trying to send a gzip file on email using below command but the zipped file received on email is corrupt. mailsend -smtp $smtpip -content-type 'application/x-gzip' -mime-type "application/x-gzip" -t $receiver -f $sender -sub "$subject" -M "$MSG" -attach $file file name is ... (1 Reply)
Discussion started by: tushar.modgil
1 Replies

2. Shell Programming and Scripting

MIME Type detection for Net::SMTP

I've spent a good two weeks on trying to figure out a proper way to get the mime type of a file. The "file" command on the Sparc machine I'm working on is an older version and does not support the --mime flag. It outputs things like: somefile.pdf: Adobe Portable Document Format (PDF) v1.5 ... (3 Replies)
Discussion started by: mrwatkin
3 Replies

3. Shell Programming and Scripting

Retrieving File name

Hi All.. I have a Filename as FAB1_600015_CONRAD.A0_7XYZ12345.000_LT-SWET.01_LTPA25L_20110622-161429_07_WFR12345_20110622-161429_20110712-125228.data.dis I want to get the result as... (5 Replies)
Discussion started by: asheshrocky
5 Replies

4. HP-UX

How to attach an excel file in a multipart (mime) mail

Hello. I need to send mails from hp-ux with 2 attachments: a text file and an excel file. So I'm composing a mime file which I will pipe to sendmail utility. This works fine if the only attachment is the text file (i use cat command to attach text content). But I have problems with the format... (3 Replies)
Discussion started by: elcampio
3 Replies

5. UNIX for Dummies Questions & Answers

Retrieving PID from a file

Hello I need to retrieve the content of a file in the shell script file(.sh file). I store the Process ID of the a process in file.Only the PID is available in that file. Inside the shell script i want to retireve the content(PID) and need to check for the existence of the Process.Basically... (5 Replies)
Discussion started by: appleforme1415
5 Replies

6. UNIX for Dummies Questions & Answers

Lynx - Downloading - extension handling - changing mime type?

Using Lynx, when I try to download a .rar, it confirms I want to download and its got it as an appication/rar file. However, split archives that end in .r## (.r00, .r01 ...) are not recognized as an appication/rar file and it reads the file like a .txt or .html. How can I fix this? Thanks! (2 Replies)
Discussion started by: yitzle
2 Replies

7. UNIX for Advanced & Expert Users

How to Set Mime type to mailx

I have a problem while sending attachement , it is displying Content into body of mail (Junk Data) instead of attachment (zip format) in Linux, same code is working in Sun Solaris.. I have read query in this site , need to set MIME type to mailx componment. Please help me how to set MIME type..... (1 Reply)
Discussion started by: suneel
1 Replies

8. UNIX for Advanced & Expert Users

retrieving a deleted file

hi!, is there any way to retrieve a file that I have deleted few minutes back?? I am using Solaris- 5.6.. :rolleyes: (2 Replies)
Discussion started by: jyotipg
2 Replies
Login or Register to Ask a Question